fork(4) download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n;
  7. cin >> n;
  8. int a[n];
  9. for (int i=0; i<n; i++) {
  10. cin >> a[i];
  11. }
  12. double sum=0;
  13. int f=1;
  14. for (int i=1; i<=n; i++) {
  15. f*=i;
  16. double sign = (i%2==0) ? 1 : -1;
  17. sum+=(sign*a[i-1])/f;
  18. }
  19. cout << sum << endl;
  20. return 0;
  21. }
Success #stdin #stdout 0s 3432KB
stdin
5
0 0 0 2 3
stdout
0.0583333