fork download
  1. //Q45. Write a program to find the sum of the series: 2/3 + 4/7 + 6/11 + 8/15 + ... up to n terms.
  2.  
  3. #include <stdio.h>
  4.  
  5. int main() {
  6. int n;
  7. float sum = 0;
  8. printf("Enter n: ");
  9. scanf("%d", &n);
  10.  
  11. int num = 2, den = 3;
  12. for (int i = 1; i <= n; i++) {
  13. sum += (float)num / den;
  14. num += 2;
  15. den += 4;
  16. }
  17.  
  18. printf("Sum of series = %.2f\n", sum);
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0s 5320KB
stdin
3
stdout
Enter n: Sum of series = 1.78