C语言+数学问题:如何解出y=sin(x)中的x

来源:百度知道 编辑:UC知道 时间:2024/06/04 06:09:23
即输入y,解出x

有个double asin(double)函数,返回参数的反正弦值

//输出的是弧度制 c++
//反函数 asin 包含于 math.h
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
double y;
cout << "input y between -1 and 1\n";
cin >> y;
if ( y < -1 || y > 1 )
{
cout << "wrong input\n";
return 0;
}

double x = asin(y);
cout << x << endl;
return 0;
}

x有无数个解,用asin可以得到其中一个。