// sinx.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int factorial(int num){
int a=1;
for(int i=1;i<num;i++){
a=a*(i+1);
}
return a;
}
double ssin(double t){
bool flag = true;//T减法,F加法
t=3.14159265/(180/t);//换算成弧度
double result = t;
double a=0,b=0;
double oddnum = 0;
for(int i=0;i<12;i++){//精度
oddnum = 2*(i+1)+1;
a=pow(t,oddnum);
b= (double)factorial(oddnum);
if(flag){
result = result - (a/b);
flag = false;
}
else{
result = result + (a/b);
flag = true;
}
}
return result;
}
int _tmain(int argc, _TCHAR* argv[]){
//sin(20°) = 0.34202014332566873304409961468226
double a = ssin(20);//角度
cout<<a;
system("pause");
}
vs2012