Advertisement
Spocoman

09. Numbers from 1 to 10

Sep 6th, 2023
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. Решение с for:
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     for (int i = 1; i < 11; i++) {
  9.         cout << i << endl;
  10.     }
  11.  
  12.     return 0;
  13. }
  14.  
  15. Решение с while:
  16.  
  17. #include <iostream>
  18.  
  19. using namespace std;
  20.  
  21. int main() {
  22.     int num = 1;
  23.  
  24.     while (num < 11) {
  25.         cout << num << endl;
  26.         num++;
  27.     }
  28.  
  29.     return 0;
  30. }
  31.  
  32. Решение с do/while:
  33.  
  34. #include <iostream>
  35.  
  36. using namespace std;
  37.  
  38. int main() {
  39.     int num = 1;
  40.  
  41.     do {
  42.         cout << num << endl;
  43.         num++;
  44.     } while (num < 11);
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement