C语言结果是-1.#IND00怎么回事,我应该也没有进行非法的运算呀?
#include<stdio.h>#include<math.h>main(){floatx,y,s,t,y0;intn,m;printf("Enterx:");scan...
#include<stdio.h>
#include<math.h>
main()
{
float x,y,s,t,y0;
int n,m;
printf("Enter x:");
scanf("%f",&x);
t=-1;
y=1;
s=x*x;
m=2;
n=2;
do
{
y0=y;
y=y+(t*s)/m;
s=s*x*x;
n=n+2;
m=m*n*(n-1);
t=-t;
}while(fabs(y0-y)>1e-6);
printf("%d,sin(%f)=%f\n",n,x,y);
} 展开
#include<math.h>
main()
{
float x,y,s,t,y0;
int n,m;
printf("Enter x:");
scanf("%f",&x);
t=-1;
y=1;
s=x*x;
m=2;
n=2;
do
{
y0=y;
y=y+(t*s)/m;
s=s*x*x;
n=n+2;
m=m*n*(n-1);
t=-t;
}while(fabs(y0-y)>1e-6);
printf("%d,sin(%f)=%f\n",n,x,y);
} 展开
2个回答
展开全部
主要是输入语句要用%lf
#include<stdio.h>
#include<math.h>
main()
{
double n,m,x,y,s,t,y0;
printf("Enter x:");
scanf("%lf",&x); //double的输入必须%lf
t=-1;
y=1;
s=x*x;
m=2;
n=2;
do
{
y0=y;
y=y+(t*s)/m;
s=s*x*x;
n=n+2;
m=m*n*(n-1);
t=-t;
}while(fabs(y0-y)>1e-6);
printf("%f,cos(%f)=%f\n",n,x,y);
}
展开全部
最好全部声明为double
更多追问追答
追问
#include
#include
main()
{
double n,m,x,y,s,t,y0;
printf("Enter x:");
scanf("%f",&x);
t=-1;
y=1;
s=x*x;
m=2;
n=2;
do
{
y0=y;
y=y+(t*s)/m;
s=s*x*x;
n=n+2;
m=m*n*(n-1);
t=-t;
}while(fabs(y0-y)>1e-6);
printf("%f,cos(%f)=%f\n",n,x,y);
}
还是不行😂
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询