C语言中反三角函数的调用

Python018

C语言中反三角函数的调用,第1张

包含头文件 math.h

反3角函数有 acos(double),asin(double),atan(double),atan(double,double),

返回值 double 型,弧度值。转角度要 *180.0/3.1416

例如:

#include <stdio.h>

#include<math.h>

int main()

{

double x=0.5

printf("acos=%.2lf degrees\n",acos(x) * 180.0/3.1416)

printf("asin=%.2lf degrees\n",asin(x) * 180.0/3.1416)

printf("atan=%.2lf degrees\n",atan(x) * 180.0/3.1416)

printf("atan2=%.2lf degrees\n",atan2(1.0,2.0) * 180.0/3.1416)

return 0

}

用自带的函数库

#include <stdio.h>

#include <math.h>

#define M_PI 3.14159265358979323846

int main(void)

{

    printf("%.4f\n", sin(M_PI / 2))

    printf("%.4f\n", cos(M_PI / 3))

    printf("%.4f\n", asin(1.00))

    printf("%.4f\n", acos(0.50))

    printf("%.4f\n", tan(M_PI / 4))

    printf("%.4f\n", atan(1.00))

    return 0

}

反三角函数 得到的是弧度,除 圆周率乘 180 就得 度数。

如果要算很多个 反三角函数,你可以 建一个系数 r2d.

弧度 乘 r2d 得角度。

例如:

#include <stdio.h>

#include <math.h>

int main()

{

double x,y

double pi=asin(1.0)*2.0

double r2d=180.0/pi

int i

for (i=0i<5i++){

x = i

y=atan(x) * r2d

printf("x=%g atan=%lf\n",x,y)

}

printf("==================\n")

for (i=0i<10i++){

x = i * 0.1

y=acos(x) * r2d

printf("x=%g acos=%lf\n",x,y)

}

return 0

}