Advertisement
mahatma_xande

ex06lista05

Aug 22nd, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.29 KB | None | 0 0
  1. /*
  2. It calculates the sum of the harmonic series until its n-th term s(n).
  3. */
  4.  
  5. #include <stdio.h>
  6.  
  7. int main(){
  8.  
  9.     int n;
  10.     float s = 0;
  11.  
  12.     printf("Enter n: ");
  13.     scanf("%d", &n);
  14.  
  15.     while(n > 0){
  16.         s = s + 1.0/n;
  17.         n = n - 1;
  18.     }
  19.  
  20.     printf("%f\n", s);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement