csansoon

P2.02 P59539 Harmonic numbers (1)

Sep 19th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.24 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int main() {
  6.     cout.setf(ios::fixed);
  7.     cout.precision(4);
  8.    
  9.     double n,m;
  10.     m=0;
  11.     cin >> n;
  12.    
  13.     while (n>0) {
  14.         m=m+(1/n);
  15.         n=(n-1);
  16.     }
  17.     cout << m << endl;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment