#include<iostream>usingnamespace std;doublefact(int x)//定义阶乘函数。注意是double类型{double y = x;//注意是double类型for(int i = x-1; i >0; i--)
y *= i;return y;};doubleMy_sin(int x)//定义sin函数。注意是double类型{double y =0;//注意是double类型int i =1;double n =pow(x, i)/fact(i);//初始化n的值为第一项的值。注意不能赋值为0,否则while循环不执行while(n >1e-6)//多项式n的值小于10^6时停止循环(数值已收敛){
n =pow(x, i)/fact(i);if(i %4==1)
y += n;elseif(i %4==3)
y -= n;
i++;};return y;};doublefun_k(float r,float s)//定义函数。注意是double类型{double k;//注意是double类型if(pow(r,2)<=pow(s,2))
k =pow((pow(My_sin(r),2)+pow(My_sin(s),2)),0.5);else k =0.5*sin(r * s);return k;}intmain(){float r, s ,k;
cout <<"Please input value of r:"<< endl;
cin >> r;
cout <<"Please input value of s:"<< endl;
cin >> s;
k =fun_k(r, s);
cout <<"value of k is:"<< k;}