BIBBY 發問時間： 電腦與網際網路程式設計 · 1 0 年前

# c++的sin cos tan cot 比較大小

### 2 個解答

• 最佳解答

#include <iostream>

#include <math.h>

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;

}

• 1 0 年前

哇塞！

又是可怕的資料結構，要寫好多的節點程式碼…

＞＿＜！