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