调用math.h中的三角函数,需要将角度值变换为弧度值,代码如下:
#includestdio.h
#includemath.h
int main()
{
float st,a;
scanf("%f",st);
printf("sin(st)=%f\n", sin(a));
printf("cos(st)=%f\n", cos(a));
return 0;
}
在C语言中要使用三角函数的话,首先要包含math.h头文件.
要用以下的语句:
double x;
C语言中的三角函数计算需要将角度转弧度,,比如以下代码是计算sin()的值:
#include"stdio.h"
#include"math.h"
main()
int i;
float t;
printf("请输入要计算的角度:");
scanf("%d",i);
printf("sin(%d)=%f",i,t);
要用三角函数请在程序前面包含math.h,可以写:#includemath.h
由于cos和sin函数的参数和返回值都是double型的,请定义相关变量:double x,y;
由于cos和sin函数的参数都是弧度制的请注意将角度转换为弧度计算:
math.h里的三角函数用的单位是弧度,你貌似错今天这一节. 答案补充 Example
*/
#include math.h
#include stdio.h
void main( void )
double x, y;
y = sin( x );
printf( "sin( %f ) = %f\n", x, y );
y = sinh( x );
printf( "sinh( %f ) = %f\n",x, y );
y = cos( x );
printf( "cos( %f ) = %f\n", x, y );
y = cosh( x );
printf( "cosh( %f ) = %f\n",x, y );
} 答案补充 Output
Parameter
x
Angle in radians
以上就是土嘎嘎小编为大家整理的三角函数在C语言怎样运用相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!