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