純C/C++ sin、cos和『角度(degree)轉弳度(radian)』的教學
純C/C++ sin、cos和『角度(degree)轉弳度(radian)』的教學
資料來源:http://stackoverflow.com/questions/9347947/problems-with-math-h
線上執行結果: http://codepad.org/HD6jX0YY
Code
#include <cmath> #include <iostream> using namespace std; const double PI=3.14159;//常數定義宣告 double degrees_to_radian(double deg) { return deg * PI / 180.0; } int main() { cout << "sin(45.0) = " << sin(degrees_to_radian(45)) << endl; cout << "cos(45.0) = " << cos(degrees_to_radian(45)) << endl; }