- 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庫 - asin() 函式
C 的數學庫函式asin()用於返回傳入引數'arg'的反正弦(反正弦)值(以弧度表示),範圍在[−π/2, π/2]。
反正弦,也稱為反正弦函式。它是正弦函式的反函式,它反轉正弦函式的效果。它表示為sin−1(x) 或 asin(x)。
對於範圍在[−1, 1]內的給定值'arg',反正弦函式sin−1(arg)返回範圍在[−π/2, π/2]內的角度θ。
語法
以下是C asin()函式的語法:
double asin( double arg );
引數
此函式接受單個引數:
-
arg − 這是要計算反正弦的引數。它將是double型別,並且應在[-1, 1]範圍內。
如果沒有錯誤發生,則返回引數 (arg) 的反正弦值,範圍為 [-π/2, +π/2] 弧度。
返回值
示例 1
以下是一個基本的 C 程式,用於演示如何使用asin() 獲取以弧度表示的角度。
#include <stdio.h>
#include <math.h>
int main() {
double arg = 1.0;
double res = asin(arg);
printf("The arc sine of %f is %f radians.\n", arg, res);
return 0;
}
輸出
以下是輸出:
The arc sine of 1.000000 is 1.570796 radians.
示例 2
讓我們建立一個另一個示例,我們使用asin()函式獲取以弧度表示的反正弦值,然後轉換為度數。
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int main() {
double k = 0.5;
double res = asin(k);
// Convert radians to degrees
double val = (res * 180) / PI;
printf("The arcsine of %f is %f radians or degree %f degree. \n", k, res, val);
return 0;
}
輸出
以下是輸出:
The arcsine of 0.500000 is 0.523599 radians or degree 30.000000 degree.
示例 3
現在,建立一個另一個 C 程式來顯示反正弦值。如果'k'在-1到1之間,則顯示反正弦值,否則顯示“無效輸入!”。
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int main() {
double k = -5.0;
if (k >= -1.0 && k <= 1.0) {
double res = asin(k);
double val_degrees = (res * 180.0) / PI;
printf("The arcsine of %.2f is %.6f radians or %.6f degrees\n", k, res, val_degrees);
} else {
printf("Invalid input! The value must be between -1 and 1.\n");
}
return 0;
}
輸出
以下是輸出:
Invalid input! The value must be between -1 and 1.
廣告