Home » » Unlabelled
» Write a program to compute sinx for given x. The user should supply x and a positive integer n. We compute the sine of x using the series and the computation should use all terms in the series up through the term involving x sin x = x - x3/3! + x5/5! - x7/7!+x9/9! .........
#include<iostream>usingnamespacestd;intmain(){inti,j,n,fact,sign=-1;floatx,p,sum=0;cout<<"Enter the value of x : ";cin>>x;cout<<"Enter the value of n : ";cin>>n;for(i=1;i<=n;i+=2){p=1;fact=1;for(j=1;j<=i;j++){p=p*x;fact=fact*j;}sign=-1*sign;sum+=sign*p/fact;}cout<<"sin "<<x<<"="<<sum;return0;
}
The Output Is:
Enter the value of x : 1
Enter the value of n : 10
sin 1 = 0.841471
funny
ReplyDelete