Advertisement
RobertDeMilo

WB.13

Sep 3rd, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.  
  9.     cin >> n;
  10.  
  11.     if (n >= 1)
  12.     {
  13.         int sum = 0;
  14.         while (n > 0)
  15.         {
  16.             sum += n;
  17.             --n;
  18.         }
  19.         cout << sum;
  20.     }
  21.     else
  22.     {
  23.         cout << "Please, enter positive number";
  24.     }
  25. ********************************************************************************
  26.     int a = 5;
  27.     int b;
  28.  
  29.     do
  30.     {
  31.         cout << "Guess the number: ";
  32.         cin >> b;
  33.     } while (a != b);
  34.  
  35.     cout << "You are right!";
  36.  
  37.     return 0;
  38. }
Tags: while do-while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement