Advertisement
LisunovaMaryna

lab1.3 c++

Sep 30th, 2023
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int NumM, NumK, Num;
  8.     bool IsCorrect;
  9.     Num = 4;
  10.     NumK = 0;
  11.     cout << "Given an integer m > 10. Find the largest integer k for which 4^k <
  12.             m.\n";
  13.     cout << "Enter integer (>10): ";
  14.     do
  15.     {
  16.         IsCorrect = false;
  17.         cin >> NumM;
  18.         if ((cin.fail()) or (NumM < 10))
  19.         {
  20.             IsCorrect = true;
  21.             cout << "Incorrect value. Enter the number: ";
  22.         }
  23.         cin.clear();
  24.         while (cin.get() != '\n');
  25.     } while (IsCorrect);
  26.  
  27.     while (Num < NumM)
  28.     {
  29.         Num = Num * 4;
  30.         NumK = NumK + 1;
  31.     }
  32.     cout << NumK;
  33.  
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement