Firstly I have defined pi and a function called fact for finding factorial values. Using Taylor series we have sin(x)= x-(x^3)/3! + (x^5)/5! - ....... upto 10th term. nemo is the abbreviation for numerator and deno for denominator for the following terms. Value stores the value of sin(x).
Here's the code that I have tried writing:
#include<stdio.h>
#include<math.h>
#define pi 3.142
int fact(int);
int main()
{
int i, j;
float x, value, nume, deno;
printf("Enter the value for sin x in degrees: \t");
scanf("%f", &x);
x= (pi * x)/100;
value = 0;
i=1;
while(i== 1)
value = value+ x;
i = 2;
for(i=2; i<=10; i++)
{
while (i%2 !=0)
{
nume = pow(x,i);
deno = fact(i);
for(j = 2; j<i; j++)
if(j%2 == 0)
value = value - (nume/deno);
else
value = value + (nume/deno);
nume = 0;
deno = 0;
}
}
printf("value of sin x is : \t");
printf("%f", value);
return 0;
}
int fact(int n)
{
if(n==0)
return 1;
else
return (n*fact(n-1));
}
Not being able to figure out what's going wrong. When I'm executing it only prints Enter the value of sin x in degrees Please help me to fix this code.