Please help me find the sine series .
My program is:

#include<stdio.h>
#include<conio.h>
#include<math.h>
float facto(int a);
int main()

{
     int n,g,k,y;
     y=1;
     float s=0.0;
     float f=0.0;
     float l =0.0;
     float x;
     int t=0;
     
       printf(" limit is \n");
     scanf("%d",&n);
       
       printf(" no. is \n");
        scanf("%d",&x);
     x=3.14*(x/180.0);
     
        while(y<(n+1))
       {     g=y;
             if(g%2==0)
              t=-1;
              else
              t=1;
             k=2*g;
             l = facto(g+1);
            f=(pow(x,(g+1))/l)*(t);
            s = s+f;
            y+=2;
          }  
       
          printf("\n sum is %d",s);
          system("pause");
          return 0;
          }
 float facto(int c)
{     int d=1;
       float fact = 1.0;
       while(d<(c+1))
       {
       fact=fact*d;
       d++;}
    return(fact);
}

I am unable to get the correct thing.

For instance , if I gave limit 2 and no. as 34 or any other no. , the output is always 0.
I cant understand this , what is my mistake?

PLEASE help me find it out!:(

Thanks in advance,
hinduengg

Recommended Answers

All 4 Replies

float x;
scanf("%d",&x);

x is a float value so in the scanf statement u should use %f instead of %d.

.....cheers

i dont think that only part is creating the problem.....it has one more problem including the above stated:

Max Value of Sine function is 1
It is due the the answer is less than zero and you are printing its integer value thats is always zero....
you wrote
printf("\n sum is %d",s);
instead it would be
printf("\n sum is %f",s);

And a little piece of advice. When working with decimal numbers, don't use float, instead use more precise double.

Thank you very very much . :)
May God bless you all.

Regards,
hinduengg

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.