C ++中的atan()函數(shù)以弧度形式返回?cái)?shù)字(參數(shù))的反正切值。
此函數(shù)在<cmath>頭文件中定義。
[數(shù)學(xué)] tan-1x = atan(x) [C++];
double atan(double x); float atan(float x); long double atan(long double x); double atan (T x); //為整型
atan()函數(shù)采用一個(gè)強(qiáng)制性參數(shù)(可以為正,負(fù)或零)
atan()函數(shù)返回[-π/ 2,π/ 2]范圍內(nèi)的值。
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x = 57.74, result;
result = atan(x);
cout << "atan(x) = " << result << " radians" << endl;
//輸出度數(shù)
cout << "atan(x) = " << result*180/3.1415 << " degrees" << endl;
return 0;
}運(yùn)行該程序時(shí),輸出為:
atan(x) = 1.55348 radians atan(x) = 89.0104 degrees
#include <iostream>
#include <cmath>
#define PI 3.141592654
using namespace std;
int main()
{
int x = 14;
double result;
result = atan(x);
cout << "atan(x) = " << result << " radians" << endl;
//輸出度數(shù)
cout << "atan(x) = " << result*180/3.1415 << " degrees" << endl;
return 0;
}運(yùn)行該程序時(shí),輸出為:
atan(x) = 1.49949 radians atan(x) = 85.9169 degrees