find the value of cosx by using the inbuilt function
#include <stdio.h>
#include <cmath.h>
int factorial(int n)
{
return n == 1 ? 1 : n * factorial(n - 1);
}
double cos(double radian)
{
// using taylor's series
return 1 - pow(radian, 2) / factorial(2) + pow(radian, 4) / factorial(4) - pow(radian, 4) / factorial(4);
}
int main()
{
printf("%.6f", cos(PI));
return 0;
}
Comments
Leave a comment