Take a look at this....hope it helps
Code:
//The code below calculates the cosine of 50000000 random values
//using both a look up table, which is calculated at the beginning
//of the program, and using the normal cos function during runtime.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
//Declare look up table
double COSTable[360]; //360 elements for all angles between 0 and 359.
int Number;
//Calculate look up table
cout << "Calculating Cosine look up table..." << endl;
for(Number = 0; Number < 360; Number++)
{
COSTable[Number] = cos(Number * 3.14159 / 180);
}
//Calculate Cosine of 50000000 values using look up table
// and then using cos.
cout << "Calculating cosine of 50000000 random values using look"
<< " up table..." << endl;
//Look up table
for(Number = 0; Number < 50000000; Number++)
{
COSTable[rand() % 360];
}
cout << "Complete..." << endl;
cout << "Calculating cosine of 50000000 random values using cos"
<< " function..." << endl;
//cos function
for(Number = 0; Number < 50000000; Number++)
{
cos(double(rand() % 360));
}
cout << "Complete..." << endl;
return 0;
}