Friday, October 30, 2009

Evaluating Sin(x) series

Write a C function to evaluate the sin series




void main()
{
float sin(float);
float d,e;
printf("\nInput x value into sin(x) to find its result");
scanf("%f",&d);
e=sin(d);
printf("\nThe result is %f",e);
}
float fact(float x)
{
int f;
if(x==1)
return(1);

else
f=x*fact(x-1);

return(f);
}

float power(float y,float z)
{
float w;
if(z==0)
return(1);
if(z==1)
return(y);
w=y*(power(y,z-1));
return(w);
}

float sin(float a)
{ float fact(float);
float b;
float power(float,float);
b=a-(power(a,3)/fact(3.0))+(power(a,5)/fact(5.0))-(power(a,7)/fact(7.0))+(power(a,9)/fact(9.0));
return(b);
}

2 comments:

  1. can you please explain this part.

    float power(float y,float z)
    {
    float w;
    if(z==0)
    return(1);
    if(z==1)
    return(y);
    w=y*(power(y,z-1));
    return(w);



    i understood till return(y).
    after that?

    ReplyDelete
  2. after y just think about next (if else )

    ReplyDelete