Spicke

Project Number 7

Dec 13th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     setlocale(LC_ALL, "Russian");
  8.     double a, s;
  9.     int k;
  10.     do {
  11.         cout << "Введите вещественное положительное число A = ";
  12.         cin >> a;
  13.     } while( a < 1.0);
  14.     s = 0.0;
  15.     k = 0;
  16.     while (s < a) {
  17.         k++;
  18.         s = s + (1.0 / k);
  19.     }
  20.     s = s - (1.0 / k);
  21.     k = k - 1;
  22.     cout << "K = " << k << " Сумма = " << fixed << s << endl;
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment