fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double calculate_series(int n) {
  5. double sum = 0.0;
  6. for (int i = 0; i < n; i++) {
  7. sum += pow(-1, i) / (2 * i + 1);
  8. }
  9. return 4 * sum;
  10. }
  11.  
  12. int main() {
  13. int n1 = 3, n2 = 10;
  14. printf("x(%d) = %.6f\n", n1, calculate_series(n1));
  15. printf("x(%d) = %.6f\n", n2, calculate_series(n2));
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
x(3) = 3.466667
x(10) = 3.041840