Cosine Calculation without cmath library
i am a computer science student. I assigned to do a project where by
create small program using C++ language, which will ask for degree or
radians and have to out the sin, cos and tan value. But i must only use
#include <iostream>. The sine value working fine. The cosine value is the
problem. These are the codes i used to calculate :
float rad = radian value;
float func_cos (float rad)
{
float cos;
int i = 0;
float sum = 0;
float x = rad;
while (fabs(x) > 0.000001)
{
i = i + 2;
x = -(x) * ((rad*rad)/(i*(i-1)));
sum = (sum) + (x);
}
cos = 1 - sum;
return cos;
}
Please help me.. thank you so much.
No comments:
Post a Comment