公式错误
下面一个程序求一个函数当r*r<=s*s时, k=sqrt(sin(r)*sin(r)+sin(s)*sin(s))
当r*r>s*s时, k= sin(r*s)/2;
程序编译时没错,运算结果不对,请帮忙看看
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
long factorial(int n);
double tSin(double x);
int main()
{
double r;
double s;
double result;
cout<<"Enter r and s:"<<endl;
cin>>r>>s;
if(r*r <= s*s)
result = sqrt(tSin(r)*tSin(r) + tSin(s)*tSin(s));
else
result = tSin(r * s) / 2;
cout<<"result= "<<result;
return 0;
}
long factorial(int n)
{
long f;
if(n < 0)
{
cout<<"Data error,please enter again!"<<endl;
exit(-1);
}
else if(n == 0)
f = 1;
else
f = factorial(n - 1) * n;
return f;
}
double tSin(double x)
{
int den = 1;//fenmu
double num = x;//fenzi
double sqr = x * x;
double sinResult;
int flag = -1;
double fun = num / den;
while(fabs(fun) > 1e-6)
{
sinResult += fun;
num *= sqr;
den = factorial(den + 2) * flag;
fun = num / den;
}
return sinResult;
}