当前位置:首页 » 编程语言 » c语言调用三角函数
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言调用三角函数

发布时间: 2022-05-29 09:40:56

‘壹’ 如何用c语言实现三角函数的计算

math.h里的三角函数用的单位是弧度,你貌似错在这里。 答案补充 Example

/* SINCOS.C: This program displays the sine, hyperbolic
* sine, cosine, and hyperbolic cosine of pi / 2.
*/

#include <math.h>
#include <stdio.h>

void main( void )
{
double pi = 3.1415926535;
double x, y;

x = pi / 2;
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

sin( 1.570796 ) = 1.000000
sinh( 1.570796 ) = 2.301299
cos( 1.570796 ) = 0.000000
cosh( 1.570796 ) = 2.509178

Parameter

x

Angle in radians

‘贰’ 用C语言实现三角函数及反三角函数怎么实现

包含头文件math.h,然后就可以使用sin、asin等这些库函数了,那些三角函数都有,直接引用即可。注意它们的输入参数是double型或double型弧度。

‘叁’ C语言怎样表示三角函数计算(注:要用“角度制”表示)编出代码

调用math.h中的三角函数,需要将角度值变换为弧度值,代码如下:
#include<stdio.h>
#include<math.h>
#define PI 3.14159265359

int main()
{
float st,a;
scanf("%f",&st);
a = st * PI/180;
printf("sin(st)=%f\n", sin(a));
printf("cos(st)=%f\n", cos(a));
return 0;
}

‘肆’ c程序里的三角函数的调用格式

加入#include <math.h>
头文件就可以直接调用,产生为double类型,返回值也为double类型。

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

反3角函数有 acos(double),asin(double),atan(double),atan(double,double),返回值 double 型,弧度值。转角度要 *180.0/3.1416。

例如:

1、#include <stdio.h>

2、#include<stdlib.h>

3、#include<math.h>

4、int main()

5、{double x=0.5;

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

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

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

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

return 0;}

‘陆’ C语言三角函数

帮你更正一下: int main() { const double pi=3.14; //定义pi的值 double a; a=sin(45*pi/180); //角度转化为弧度 printf("%f",a); //printf的正确格式 }

‘柒’ 如何用C语言实现三角函数的计算

math.h里的三角函数用的单位是弧度,你貌似错在这里。 答案补充 Example

/* SINCOS.C: This program displays the sine, hyperbolic
* sine, cosine, and hyperbolic cosine of pi / 2.
*/

#include <math.h>
#include <stdio.h>

void main( void )
{
double pi = 3.1415926535;
double x, y;

x = pi / 2;
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

sin( 1.570796 ) = 1.000000
sinh( 1.570796 ) = 2.301299
cos( 1.570796 ) = 0.000000
cosh( 1.570796 ) = 2.509178

Parameter

x

Angle in radians

‘捌’ c语言计算器怎样做三角函数功能

很简单的,比如你已经有一个表达式char exp[];
那么 char * s = strstr(exp, "sin");
if(s) {
执行sin(alpha)
}
就可以了
strstr是一个字符串函数,用于查找字符串内与关键字匹配的那个位置
比如char exp[] = "cos(a) + sin(b) - tan(c)";
那么char * s = strstr(exp, "sin");
printf(s)的结果是:
sin(b) - tan(c)

‘玖’ c语言编写三角函数

求sin的:参考下 #include<stdio.h> void main() { double x,a,b,sum=0; printf("请输入x的弧度值:\n"); scanf("%lf",&x); int i,j,count=0; for(i=1;;i+=2) { count++; a=b=1; for(j=1;j<=i;j++) { a*=x; b*=(double)j; } if(a/b<0.0000001) break; else { if(count%2==0) sum-=a/b; else sum+=a/b; } } printf("%lf\n",sum); }

‘拾’ c语言编程中的三角函数怎么输入

开头必须有一个数学函数库#include<math.h>

然后一般常用的
sin(x)
cos(x)
tan(x)

其中的x必须要以弧度为单位。如果以“度”为单位,比如说求30度的正弦值,要用
sin(x*180/3.1415926)的形式

arcsin(x)
arccos(x)
arctan(x)
arccot(x)

以上四个则是相应的反三角函数,函数值的单位也是弧度。若要求arctan(1)的度数,要用以下的形式:arctan(1)*180/3.1415926

(10)c语言调用三角函数扩展阅读

C语言的三角函数库采用的单位都是弧度,如果要使用角度,就必须转换,从角度转换成弧度,或者是重写一个三角函数库。

在调用三角函数之前先把角度换算成弧度,调用反三角函数之后把弧度换算成角度就可以了。可以用 pi = 4.0 * atan(1) 算出pi,用 a = d /180.0*pi 转换角度到弧度。

例如: sin(45 /180.0*pi); 就是计算的sin45。