大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
#includestdio.h
目前成都创新互联已为上千的企业提供了网站建设、域名、虚拟空间、成都网站托管、企业网站设计、安化网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
#includemath.h
double sin(double);
double nResult(double,double);
int main()
{
double x=0;
scanf("%lf",x);
printf("sin(%lf)=%lf\n",x,sin(x));
return 0;
}
double sin(double x)
{
//sin(x)=x-x^3/3!+x^5/5!-x^7/7!+……+(-1)(n^2n+1)/(2n+1)!+……
int i=0;
double result=0,n=0;
while( fabs( n=nResult(x,2*++i-1) ) 0e-5 )//绝对值大于10^-5次方就循环
result+=(i%2==1)?n:-n;
return result;
}
double nResult(double x,double n)
{
//(n^2n+1)/(2n+1)!也就是n/1*n/2*n/3*n/4*.....n/(2n+1)
return n==1?x:nResult(x,n-1)*x/n;
}
源代码如下:
#include#include#define EX 0.000001
#define PI 3.14159265
int main()
{
double x=0.0, temp=1.0, sin=0.0;
int i;
printf("Please input a degree:");
scanf("%lf",x);
x=x*PI/180;
temp=x;i=0 ;
while ( fabs(temp) EX ) ...{
sin += temp;
i += 2;
temp = (-1) * temp*x*x/( (i+1)*(i) );
}
printf("sin(%lf) = %lf ",x,sin);
printf("The number is %d ",i);
return 0;
}
扩展资料
C语言编写一个程序输出一个正方形的源代码如下:
#include
int main()
{
int i,j,n;
scanf("%d",n);
for(i=0;i
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
#include stdio.h
#include math.h
#define EX 0.000001
#define PI 3.14159265
int main()
...{
double x=0.0, temp=1.0, sin=0.0;
int i;
printf("Please input a degree:");
scanf("%lf",x);
x=x*PI/180;
temp=x;
i=0 ;
while ( fabs(temp) EX ) ...{
sin += temp;
i += 2;
temp = (-1) * temp*x*x/( (i+1)*(i) );
}
printf("sin(%lf) = %lf ",x,sin);
printf("The number is %d ",i);
return 0;
}