fork download
  1. //Q44. Write a program to find the sum of the series: 1 + 3/4 + 5/6 + 7/8 + … up to n terms.
  2. #include <stdio.h>
  3.  
  4. int main() {
  5. int n;
  6.  
  7. double sum = 0.0;
  8.  
  9. scanf ("%d",&n);
  10.  
  11. for (int i = 1; i <= n; i++) {
  12.  
  13. sum += (2 * 1 - 1) / (double)(2 * 1);
  14.  
  15. }
  16.  
  17. printf("Approximate sum: %.1f\n", sum);
  18.  
  19. return 0;
  20.  
  21. }
Success #stdin #stdout 0.01s 5288KB
stdin
5
stdout
Approximate sum: 2.5