Advertisement
Dinmrmr

Untitled

Sep 25th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3.  
  4. using namespace std;
  5.  
  6. float SUMM(float n) {
  7.     //float sum = 0;
  8.     if (n == 0)
  9.         return 1;
  10.     if (n > 1.0) {
  11.         return 1.0 + SUMM(1.0 / n);
  12.         n--;
  13.     }
  14. }
  15.  
  16. int main() {
  17.     setlocale(LC_ALL, "russian");
  18.     float sum = 0;
  19.     float n;
  20.     cout << "Enter n: ";
  21.     cin >> n;
  22.     for (float i = 1; i <= n; i++) {
  23.         sum = sum + float(1 / i);
  24.     }
  25.     cout << "Sum = " << SUMM(n) << endl;
  26.     cout << "Sum = " << sum << endl;
  27.     system("pause");
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement