C语言求SIN(X)求纠错
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/13 08:37:32
C语言求SIN(X)求纠错
#include
int main()
{
double x,term;
double sin=0;
int sign=1,n=1;
scanf("%lf",&x);
term=(double)(sign*x)/n;
for(;term>=1e-5;n=n+2)
{
sin+=term;
term=sign*term*x*x/((n+1)(n+2));
sign=-sign;
}
printf("%lf",sin);
return 0;
}
-------------------Configuration:1 - Win32 Debug--------------------
Compiling...
1.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(14) :error C2064:term does not evaluate to a function
Error executing cl.exe.
1.obj - 1 error(s),0 warning(s)
#include
int main()
{
double x,term;
double sin=0;
int sign=1,n=1;
scanf("%lf",&x);
term=(double)(sign*x)/n;
for(;term>=1e-5;n=n+2)
{
sin+=term;
term=sign*term*x*x/((n+1)(n+2));
sign=-sign;
}
printf("%lf",sin);
return 0;
}
-------------------Configuration:1 - Win32 Debug--------------------
Compiling...
1.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\1\1.cpp(14) :error C2064:term does not evaluate to a function
Error executing cl.exe.
1.obj - 1 error(s),0 warning(s)
在数学里乘号可以省略不写,类似(n+1)(n+2)这样.
但是程序里不能省略,所以
term=sign*term*x*x/((n+1)(n+2));
应该是:
term=sign*term*x*x/((n+1)*(n+2));
但是程序里不能省略,所以
term=sign*term*x*x/((n+1)(n+2));
应该是:
term=sign*term*x*x/((n+1)*(n+2));