fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdlib>
  4.  
  5. int fac( int n )
  6. {
  7. if( !n ) return 1;
  8. return n * fac(n-1);
  9. }
  10.  
  11. double term( double a, int n )
  12. {
  13. if( !(n % 2) ) a = -a;
  14. return a / fac(n);
  15. }
  16.  
  17. int main ()
  18. {
  19. int n;
  20. std::cout << "input sequence length" << std::endl;
  21. std::cin >> n;
  22.  
  23. double a[n];
  24. double s = 0;
  25. for( int i=0; i<n; ++i )
  26. {
  27. std::cout << "input a[" << i+1 << "]";
  28. std::cin >> a[i];
  29. s += term( a[i], i+1 );
  30. }
  31. std::cout << s << std::endl;
  32. std::system("pause");
  33. return 0;
  34. }
Success #stdin #stdout #stderr 0s 2988KB
stdin
3 1.1 3.3 44.44
stdout
input sequence length
input a[1]input a[2]input a[3]6.85667
stderr
sh: pause: not found