程式碼示例:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float a,b,c,C;
cout <<"Please enter two numbers of triangle as a and b:";
cin >> a >> b;
cout <<"Please enter the angle of the triangle as A and B:";
cin >> C;
c = sqrt(a*a + b*b - 2*a*b*cos(3.1415926/180*C));
cout <<"The length of c is:"<< c <<endl;
return 0;
}
cos接受的是弧度,輸入角度乘上pi/180轉換為弧度後呼叫才能得到正確結果
程式碼示例:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float a,b,c,C;
cout <<"Please enter two numbers of triangle as a and b:";
cin >> a >> b;
cout <<"Please enter the angle of the triangle as A and B:";
cin >> C;
c = sqrt(a*a + b*b - 2*a*b*cos(3.1415926/180*C));
cout <<"The length of c is:"<< c <<endl;
return 0;
}
cos接受的是弧度,輸入角度乘上pi/180轉換為弧度後呼叫才能得到正確結果