我正在製作一個取3個無符號長長函數的函數,並應用餘弦定律來確定三角形是鈍角,銳角還是直角三角形。我應該在使用它們之前將變量加倍加倍嗎?無符號長長算術變爲雙重
void triar(unsigned long long& r,
unsigned long long x,
unsigned long long y,
unsigned long long z)
{
if(x==0 || y==0 || z==0) die("invalid triangle sides");
double t=(x*x + y*y -z*z)/(2*x*y);
t=acos (t) * (180.0/3.14159265);
if(t > 90) {
cout<<"Obtuse Triangle"<<endl;
r=t;
} else if(t < 90){
cout<<"Acute Triangle"<<endl;
r=t;
} else if(t == 90){
cout<<"Right Traingle"<<endl;
r=t;
}
}
爲什麼函數採用'unsigned long long'而不是'double'? – Troubadour