重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
求sin的:参考下 #includestdio.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/b0.0000001) break; else { if(count%2==0) sum-=a/b; else sum+=a/b; } } printf("%lf\n",sum); }
网站建设哪家好,找创新互联公司!专注于网页设计、网站建设、微信开发、小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了崂山免费建站欢迎大家使用!
求解含有三角函数的定积分c语言程序∫(1+cosπx)dx
#include stdio.h
#include math.h
#define PI (acos(-1))
#define STEP (1e-6)
double func(double x);
double inte(double up,double down,double func(double));
int main(void)
{
double up,down;
printf("%lf%lf",up,down);
printf("%lf\n",inte(1,0,func));
return 0;
}
double func(double x)
{
return 1+cos(PI*x);
}
double inte(double up,double down,double func(double))
{
double sum;
for(sum=0;down=up;down+=STEP)
{
sum+=func(down)*STEP;
}
return sum;
}
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
调用math.h中的三角函数,需要将角度值变换为弧度值,代码如下:
#includestdio.h
#includemath.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语言中的三角函数计算需要将角度转弧度,,比如以下代码是计算sin()的值:
#include"stdio.h"
#include"math.h"
#define PI 3.1415926
main()
{
int i;
float t;
printf("请输入要计算的角度:");
scanf("%d",i);
t=sin(180*i/PI);
printf("sin(%d)=%f",i,t);
}