# include <iostream>
# include <math.h>
using namespace std;
int main()
{
int count=1;
double x;
double sine, num, dem, sign, term;
sine=0;
sign = 1;
cout << "Get x: ";
cin >> x;
num = x;
dem = count;
while ( count <= 10 )
{
term = (num/dem);
sine = sine + term*sign;
num = num*x*x;
count = count + 2;
dem = dem * count * (count-1);
sign = -sign;
}
cout << "The result is: ";
cout << sine;
return 0;
}
这是我在 C++ 中为 sin x 编写的代码,有人可以指出我的错误,因为程序没有计算出正确的值,我尝试调试了几个小时,但我的努力有点徒劳,感谢您的帮助!谢谢!
*num=分子,dem=分母