According to sine series:
Where x in radians
#include<stdio.h>
#include<math.h>
float cal_Sin(float r, int a);
double factorial(int n)
{
if(n == 0)
{
return 1;
}
else
{
return n*factorial(n-1);
}
}
int main()
{
int x, n;
float radian, res;
printf("Enter the value of x in degrees \n");
scanf("%d", &x);
printf("Enter the power of end term:");
scanf("%d",&n);
// convert x to radians
radian = x * (3.14 / 180);
res = cal_Sin(radian, n);
printf("The value of sin(%d) is %f",x,res);
return 0;
}
float cal_Sin(float rad, int n)
{
float sum = rad;
int i=3, sign = -1;
while(i<=n)
{
sum = sum + sign *(pow(rad, i) / factorial (i));
sign = sign * -1;
i= i +2;
}
return sum;
}
Output
Enter the value of x in degrees
60
Enter the power of end term:10
The value of sin(60) is 0.865760
Views: 0