怎么编写,只允许使用C++标准库中的sqrt()函数sin(x)根据近似值公式求解

img

img

img


只允许使用C++标准库中的sqrt()函数sin(x)根据近似值公式求解

#include <iostream>
#define PI 3.1415926
using namespace std;
double sin(double x)
{
    double s;
    if(x>2*PI)
        x-=2*PI*(int)(x/PI/2);
    if(x*2>PI)
        if(x<PI)
            s=sin(PI-x);
        else if(x*2<PI*3)
            s=-sin(PI-x);
        else
            s=-sin(x);
    else
    {
        double a=x,b=1,t,r=0,xx=x*x,s=1,i=3;
        do
        {
            t=a/b;
            r+=t*s;
            a=a*xx;
            b=b*i;
            i+=2;
            s=s==1?-1:1;
        }while(t>1e-5);
        return r;
    }
    return s;
}
int main()
{

    double x;
    cout<<"请输入x值:";cin>>x;
    cout<<"sin(x)="<<sin(x);
    return 0;
}

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^