fork download
  1. #include <stdio.h>
  2.  
  3. double calculate_series_sum(int n) {
  4. double sum = 0.0;
  5.  
  6. for (int i = 1; i <= n; i++) {
  7. sum += 1.0 / (i * (i + 1));
  8. }
  9.  
  10. return sum;
  11. }
  12.  
  13. int main(void) {
  14. int n;
  15.  
  16. scanf("%d", &n);
  17.  
  18. double sum = calculate_series_sum(n);
  19.  
  20. printf("x(%d) = %f\n", n, sum);
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 5272KB
stdin
3
stdout
x(3) = 0.750000