Problem Statement
Write a c program to calculate the value of sin using recursion
first scan the number x and then calculate the value of sine series(using Taylor's series)
Write a c program to calculate the value of sin using recursion
first scan the number x and then calculate the value of sine series(using Taylor's series)
#include<stdio.h>
float srs(float x,int i);
float term(float x,int i);
int main()
{
float x,y;
int i;
printf("enter the value of x\n");
scanf("%f",&x);
i=1;
y=srs(x,i);
printf("the sum is equals to %f",y);
return 0;
}
float srs(float x,int i)
{
float sum=0.0;
float t;
t= term(x,i);
if(i%2==0&&t>(-.000001))
{
return 0;
}
else if(i%2!=0&&t<(.000001))
{
return 0;
}
else
{
sum=t+ srs(x,i+1);
}
return sum;
}
float term(float x,int i)
{
float tn;
int h;
tn=x;
for(h=2;h<2*i;h++)
{
tn= (x*tn)/h;
}
if(i%2==0)
{
tn= tn*(-1.0);
return tn;
}
else
{
return tn;
}
}
Excellent!
ReplyDeleteGive input in radiant.