主题:求帮助!十分感谢!
#include<math.h>
#include<stdio.h>
main()
{
int n=1;
float x;
long double sum ,term;
printf("input x:");
scanf("%f",&x);
sum=x;
term=x;
do
{
term=-term*x*x/((n+1)*(n+2));
sum=sum+term;
n=n+2;
}
while (fabs(term)>=1e-5);
printf("sin(x)=%f\n",sum);
}
为什么我的这个编程只能算到40,大于40的数就计算错误?
#include<stdio.h>
main()
{
int n=1;
float x;
long double sum ,term;
printf("input x:");
scanf("%f",&x);
sum=x;
term=x;
do
{
term=-term*x*x/((n+1)*(n+2));
sum=sum+term;
n=n+2;
}
while (fabs(term)>=1e-5);
printf("sin(x)=%f\n",sum);
}
为什么我的这个编程只能算到40,大于40的数就计算错误?