fork download
  1. /*
  2. * C program to determine and print the sum of the following harmonic series for
  3. * a given value of n: 1 + 1/3 + 1/5 + ... +1/(2n+1)
  4. */
  5. #include<stdio.h>
  6.  
  7. void main()
  8. {
  9. int n;
  10. float i, sum, t;
  11. printf("1 + 1/3 + 1/5 + ... + 1/(2n+1)\n");
  12. n=25;
  13. sum=0;
  14. for(i=0; i<=n; i++)
  15. {
  16. t=1/(2*i+1);
  17. sum=sum+t;
  18. }
  19. printf("%f",sum);
  20. }
Runtime error #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
1 + 1/3 + 1/5 + ... + 1/(2n+1)
2.610835