atanf 给我错误的答案
atanf gives me wrong answers
我正在做一本名为 C++ 游戏模块的书的第 3 章(函数)的练习。
这是我无法做的一个问题是找到 (2,4) 的 atanf(4/2),根据这本书和我的计算器应该返回 '63.42' 度。
相反,它给了我 1.107 度。
这是我的代码:
#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;
void tani(float a,float b) //Finds the Tan inverse
{
float res;
res = atanf(b / a);
cout << res << endl;
}
int main()
{
cout << "Enter The Points X and Y: " << endl;
float x, y;
cin >> x >> y; //Input
tani(x,y); //calling Function
}
它在给你正确答案 radians.Simply 转换成学位!
void tani(float a, float b) //Finds the Tan inverse
{
float res;
res = atanf(b/ a);
cout << res *(180 / 3.14) << endl;
}
atanf
,以及c++ return results in radians中的其他三角函数。 1.107 弧度是 63.426428 度,所以你的代码是正确的。
您可以通过乘以 180 再除以 Pi(<cmath>
提供的 M_PI
常量)将弧度转换为度数:
cout << res * 180.0 / M_PI << endl;
我正在做一本名为 C++ 游戏模块的书的第 3 章(函数)的练习。 这是我无法做的一个问题是找到 (2,4) 的 atanf(4/2),根据这本书和我的计算器应该返回 '63.42' 度。
相反,它给了我 1.107 度。
这是我的代码:
#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;
void tani(float a,float b) //Finds the Tan inverse
{
float res;
res = atanf(b / a);
cout << res << endl;
}
int main()
{
cout << "Enter The Points X and Y: " << endl;
float x, y;
cin >> x >> y; //Input
tani(x,y); //calling Function
}
它在给你正确答案 radians.Simply 转换成学位!
void tani(float a, float b) //Finds the Tan inverse
{
float res;
res = atanf(b/ a);
cout << res *(180 / 3.14) << endl;
}
atanf
,以及c++ return results in radians中的其他三角函数。 1.107 弧度是 63.426428 度,所以你的代码是正确的。
您可以通过乘以 180 再除以 Pi(<cmath>
提供的 M_PI
常量)将弧度转换为度数:
cout << res * 180.0 / M_PI << endl;