請比較sin30 cos45 tan60 cot25 大小順序?
請問以上這題要如何用c++ 表示出來呢?
2007-06-15 14:00:43 · 2 個解答 · 發問者 BIBBY 1 in 電腦與網際網路 ➔ 程式設計
#include
#include
class trigonometric
{
public:
char* title;
float value;
};
using namespace std;
int main()
{
trigonometric arr[4], temp;
float pi = 3.14159;
// 度
arr[0].title = "sin30: "; arr[0].value = sin(30 * (pi/180));
arr[1].title = "cos45: "; arr[1].value = cos(45 * (pi/180));
arr[2].title = "tan60: "; arr[2].value = tan(60 * (pi/180));
arr[3].title = "cot25: "; arr[3].value = 1/tan(25 * (pi/180));
/* 弳度
arr[0].title = "sin30: "; arr[0].value = sin((float)30);
arr[1].title = "cos45: "; arr[1].value = cos((float)45);
arr[2].title = "tan60: "; arr[2].value = tan((float)60);
arr[3].title = "cot25: "; arr[3].value = 1/tan((float)25);
*/
for (int in = 0; in < 4; in++)
cout << arr[in].title << arr[in].value << endl;
for(int i = 1; i <= 3; i++)
{
for(int j = 0; j < 4-i; j++)
{
if(arr[j].value < arr[j+1].value)
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
cout << endl << "大小順序:" << endl;
for (int out = 0; out < 4; out++)
cout << arr[out].title << arr[out].value << endl;
return 0;
}
2007-06-15 18:09:14 · answer #1 · answered by 這個世界越來越爛 4 · 0⤊ 0⤋
哇塞!
又是可怕的資料結構,要寫好多的節點程式碼…
>_<!
2007-06-15 16:52:32 · answer #2 · answered by Big_John-tw 7 · 0⤊ 0⤋