帮忙寻找一下这个程序的错误,谢谢
题目要求是Write a program, that after the entering of a real number x and a real number eps (the accuracy) computes
the value for sin_x (until |Term(n)|<eps complies) , using factoring over n terms.
Print x, sin_x, sin(x) and the n-th term. Use functions Fac() and Term() according to:
sin_x = Term1 + Term2 + Term3 + … = x - x3/3! + x5/5! - x7/7! + …. [ example: Fac(3) = 1.2.3 ]
#include <math.h>
#include <stdio.h>
int Fac(unsigned int i)
{
unsigned int fac = 1;
while(i)
fac *= i--;
return fac;
}
double Term(double x, unsigned int i, char last_sign)
{
if(last_sign)
{
last_sign = 0;
return pow(x,(double)i)/(double)(Fac(i));
}
else
{
last_sign = 1;
return (-1.00)*pow(x,(double)i)/(double)(Fac(i));
}
}
#define DEG2RAD(x) x*3.1415926/180.00f
int main()
{
double x,eps;
double sum=1;
double term;
unsigned int i;
char last_sign = 0;
printf("Please input your x:\t");
scanf("%lf",&x);
printf("Please input your eps:\t");
scanf("%lf",&eps);
i = 1;
term = x;
while(term < eps)
{
sum += term;
i+=2;
term = Term(x,i,last_sign);
}
printf("x is %lf, sin_x is %lf, and sin(x) is %lf\n", x, sum, sin(x));
return 0;
}
当输入X为1,eps为0.5时,最终给出的SIN_X答案为1。老师说这个是错误的,请前辈们帮忙看一下该如何修改.谢谢