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

c语言求三角函数sinxcosx

发布时间: 2022-08-14 20:01:20

1. c语言。给定x的值,求sinx+cosx的值。

直接调用数学库的 sin(x) , cos(x) 函数即可。加 头文件 math.h
#include <stdio.h>
#include <math.h>

int main()
{
double x;
double y;
printf("input x:\n");
scanf("%lf",&x);
y = sin(x) + cos(x);
printf("y=%g\n",y);
return 0;
}

2. 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); }

3. c语言能直接输入三角函数符号嘛 比如sin cos

可以的
你要在main()之前加个东西#include<math.h>

4. c语言计算三角函数

#include<stdio.h>
#include<math.h>
intmain()
{
doublen;//sincos是函数,不能定义成变量
scanf("%lf",&n);
n=sin(n);//求n的sin()值,并返回给n
printf("%lf ",n);//输出n
return0;
}

5. 如何用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

6. c语言设计2个子函数分别计算sinx和cosx,要求精度为10(—6)。在主函数中求(sin30+

doublesinx(doublex)
{
doubleresult=x,temp=x;
doubleden=x,fac=1;
intn=1,sign=1;
while((temp>1e-5)||(temp<-1e-5))
{
n++,fac*=n,den*=x;
n++,fac*=n,den*=x;
temp=den/fac;sign=-sign;
result=sign>0?result+temp:result-temp;
}
returnresult;
}

doublecosx(doublex)
{
x=1.57079-x;
returnsinx(x);
}

main()
{
doublea,b,c;
scanf("%lf",&a);
b=sinx(a);
c=cosx(a);
printf("sin(%lf)=%lf,cos(%lf)=%lf",a,b,a,c);
}

7. 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;
}

8. 用C语言输出CosX,SinX函数图像的问题,新手求解

把你的printf("*/n")改为printf("*\n"),其它的/n也改为\n看看行不行。
#include <stdio.h>
#include <math.h>
int main()
{
double y;
double x, m, i;
for(y=1;y>=-1;y-=0.1)
{
if(y>=0)
{
m=asin(y)*10;
for(x=1;x<m;x++)
printf(" ");
printf("+");
for(;x<31-m;x++)
printf(" ");
printf("*\n");
}
else
{
m=-1*asin(y)*10;
for(i=0;i<32;i++)
printf(" ");
for(x=1;x<m;x++)
printf(" ");
printf("_");
for(;x<31-m;x++)
printf(" ");
printf("m\n");
m=asin(y)*10;
for(x=1;x<m;x++)
printf(" ");
}
}
return 0;
}

9. 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