fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int fact(int x)
  4. {
  5. int i,f=1;
  6. for(i=1;i<=x;i++)
  7. f=f*i;
  8. return f;
  9. }
  10. int main()
  11. {
  12. float sum=0;
  13. float x,r;
  14. cout<<"enter the value of x";
  15. cin>>x;
  16. int limit;
  17. cout<<"enter the limit";
  18. cin>>limit; int j;
  19. r=x;
  20. x=x*(3.1416/180);
  21. for(int i=1,j=1;i<=limit;i++,j=j+2)
  22. {
  23. if(i%2!=0)
  24. {
  25. sum=sum+pow(x,j)/fact(j);
  26. }
  27. else{
  28. sum=sum-pow(x,j)/fact(j);
  29.  
  30. }
  31. }
  32. cout<<setprecision(4)<<"sin("<<r<<")= "<<sum<<endl;
  33. }
Success #stdin #stdout 0.01s 5516KB
stdin
30
4
stdout
enter the value of xenter the limitsin(30)= 0.5