
#include <stdio.h>
#include <math.h>
long double jc(int n)
{
long double jc = 1;
for(int i=1;i<=n;i++)
jc *= i;
return jc;
}
int main()
{
int flag = 1,n=1;
double item,sinx=0;
float x;
scanf("%f",&x);
item = x;
while(item > 1e-5)
{
sinx += flag * item;
item = pow(x,2*n+1)/jc(2*n+1);
flag = flag * -1;
n+=2;
}
printf("sin(%f)=%lf\n",x,sinx);
return 0;
}
#include<iostream>
#include<cmath> //具有c++标准库中数学函数的说明
using namespace std;
const double TINY_VALUE = 1e-6;
double tsin(double x)
{
double g = 0; //g为sinx()最终结果
double t = x; //初始值x赋给t
int n = 1; //n 用于求分母
do{
g += t;
n++;
t = -t * x * x / (2 * n - 1) / (2 * n - 2);
}while(fabs(t) >= TINY_VALUE); //fabs()求double型变量的绝对值
return g;
}
int main()
{
double k, r, s;
cout << "r=";
cin >> r;
cout << "s=";
cin >> s;
if(r * r <= s * s)
{
k = sqrt(tsin(r) * tsin(r) + tsin(s) * tsin(s));
}
else
{
k = tsin(r * s) / 2;
}
cout << k << endl;
return 0;
}