C语言求SIN(X)求纠错#includeint 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;}---------------
C语言求SIN(X)求纠错#includeint 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;}---------------
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)
C语言求SIN(X)求纠错#includeint 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;}---------------
在数学里乘号可以省略不写,类似(n+1)(n+2)这样.
但是程序里不能省略,所以
term=sign*term*x*x/((n+1)(n+2));
应该是:
term=sign*term*x*x/((n+1)*(n+2));