比較大小

Q:比較與輸出$sin25^\circ$與$cos70^\circ$的大小

#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char *argv[])
{
const int max = 2;
int l, i, j, k;
double funBuffer;
char strBuffer[8];
double a1 = (3.1415926) * 25 / 180;
double a2 = (3.1415926) * 70 / 180;
double fun[max] = {sin(a1), cos(a2)};
char str[max][8] = {"sin(25)", "cos(70)"};
for (l=0; l<max; l++)
cout << str[l] << " = " << fun[l] << endl;
cout << endl;
for (i=0; i<max-1; i++)
for (j=i; j<max; j++)
if (fun[i] > fun[j])
{
funBuffer = fun[i];
fun[i] = fun[j];
fun[j] = funBuffer;
for (k=0; k<8; k++)
{
strBuffer[k] = str[i][k];
str[i][k] = str[j][k];
str[j][k] = strBuffer[k];
}
}
for (i = 0; i<max; i++)
{
cout << str[i];
if (i<max-1)
cout << " < ";
}
cout << endl;

    system("PAUSE");
    return EXIT_SUCCESS;
}

這個網誌中的熱門文章

使用memset加快二維陣列初始

TCGS b004: 一個都不能少

UVA Q11614 - Etruscan Warriors Never Play Chess