- C標準庫
- C庫 - 首頁
- C庫 - <assert.h>
- C庫 - <complex.h>
- C庫 - <ctype.h>
- C庫 - <errno.h>
- C庫 - <fenv.h>
- C庫 - <float.h>
- C庫 - <inttypes.h>
- C庫 - <iso646.h>
- C庫 - <limits.h>
- C庫 - <locale.h>
- C庫 - <math.h>
- C庫 - <setjmp.h>
- C庫 - <signal.h>
- C庫 - <stdalign.h>
- C庫 - <stdarg.h>
- C庫 - <stdbool.h>
- C庫 - <stddef.h>
- C庫 - <stdio.h>
- C庫 - <stdlib.h>
- C庫 - <string.h>
- C庫 - <tgmath.h>
- C庫 - <time.h>
- C庫 - <wctype.h>
- C程式設計資源
- C程式設計 - 教程
- C - 有用資源
C庫 - atan() 函式
C語言math庫的atan()函式用於返回傳入引數'arg'的反正切值(反三角函式),結果以弧度表示,範圍在[-π/2, +π/2]之間。
反正切,也稱為反正切函式。它是正切函式的反函式,反轉正切函式的作用。
語法
以下是C語言atan()函式的語法:
double atan( double arg );
引數
此函式接受單個引數:
-
arg − 表示一個浮點數。
返回值
如果沒有錯誤發生,則返回引數 (arg) 的反正切值,結果以弧度表示,範圍在 [-π/2, +π/2] 之間。如果由於下溢而發生範圍錯誤,則返回正確的結果(舍入後)。
示例 1
以下是一個基本的C程式,演示瞭如何使用atan()獲取以弧度表示的角度。
#include <stdio.h>
#include <math.h>
int main() {
double arg = 1.0;
double res = atan(arg);
printf("The arc tangent of %f is %f radians.\n", arg, res);
return 0;
}
輸出
以下是輸出:
The arc tangent of 1.000000 is 0.785398 radians.
示例 2
讓我們建立另一個示例,我們使用atan()函式來獲取陣列中每個元素的反正切值。
#include <stdio.h>
#include <math.h>
int main() {
double arg[] = {10, 20, 25, 30};
int length = sizeof(arg) / sizeof(arg[0]);
for(int i=0; i<length; i++){
double res = atan(arg[i]);
printf("The arc tangent of %f is %f radians.\n", arg[i], res);
}
return 0;
}
輸出
以下是輸出:
The arc tangent of 10.000000 is 1.471128 radians. The arc tangent of 20.000000 is 1.520838 radians. The arc tangent of 25.000000 is 1.530818 radians. The arc tangent of 30.000000 is 1.537475 radians.
示例 3
現在,建立一個另一個C程式來顯示反正切值以度表示。
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int main () {
double arg, res_in_degree, val;
arg = 1.0;
val = 180.0 / PI;
res_in_degree = atan (arg) * val;
printf("The arc tangent of %lf is %lf degrees", arg, res_in_degree);
return(0);
}
輸出
以下是輸出:
The arc tangent of 1.000000 is 45.000000 degrees
廣告