Advertisement
alias3glw

Taylor Seno

May 25th, 2015
5,137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <iomanip>
  4. using namespace std;
  5. int main(int argc, char** argv) {
  6.     long long int i,j,a=3,n,fact=1; //Se usa el long long int por las limitaciones de los numeros
  7.     long double seno;
  8.     long double x;
  9.     cin>>x;
  10.     cin>>n;
  11.     seno=x;
  12.     for ( i=1; i<=n ; i++){
  13.         fact=1;
  14.         //Factorial
  15.         for (j=1 ; j<=a ; j++){
  16.             fact=fact*j;   
  17.         }
  18.         if (i%2==0){
  19.             seno=seno + (pow(x,a))/fact;
  20.         } else {
  21.             seno=seno - pow(x,a)/fact; 
  22.         }
  23.         a=a+2;
  24.     }
  25.     cout<<fixed<<setprecision(11);
  26.     cout<<seno<<endl;
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement