//_15_do_while语句
//_15_main.cpp
//本例原题是:sin(x)=x-(x^3)/3!+(x^5)/5!-(x^7)/7!......
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
double s = 0;//多项式的值
double t;//每一项的值
int j = 1;//每一项中阶乘的值
double x;//自变量
int n=1;//1.2.3.4.5.6.7.8.9.10.......
printf("输入变量x:");
scanf("%lf",&x);//输入的时候double类型数据用%lf,float类型用%f类型
t=x;
s = x;
do{
n=n+2;
t = t*(-x*x)/(((float)(n-1))*(float)n);
s = s + t;
}while(fabs(t)>=1e-8);
printf("sin(%f)=%f\n",x,s);
system("pause");
return 0;
}