fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int n;
  5. double sum = 0.0;
  6. double term = 1.0;
  7.  
  8. printf("Enter the value of n: ");
  9. scanf("%d", &n);
  10.  
  11. for (int i = 0; i <= n; i++) {
  12. sum += term;
  13. term /= 2; // each term is 1 / 2^i
  14. }
  15.  
  16. printf("Sum of the series is: %lf\n", sum);
  17.  
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0s 5312KB
stdin
 
stdout
Enter the value of n: Sum of the series is: 2.000000