#include <iostream>
double myabs(double c);
double mysin(double x);
using namespace std;
const double pi=3.1415926;
int main()
{
cout << "sin(л/2)的值为"<<mysin(pi/2)<<endl;
cout<<"sin(56°)的值为"<<mysin(pi*2*56/360)<<endl;
return 0;
}
double myabs(double c);
double mysin(double x)
{
double sum = x, fact = x, n;
int i = 1, s = 1, m = 1;
do
{
m = m * (i + 1) * (i + 2);
fact=fact*x*x;
n = fact / m;
s = -s;
sum = sum + s * n;
i = i + 2;
}
while (myabs(n) > 1e-5);
return sum;
}
double myabs(double c)
{
if (c < 0)
c = -c;
else
c = c;
return c;
}
第十一周项目七:太乐了
最新推荐文章于 2016-04-18 16:51:10 发布