Advertisement
Grozario

Untitled

Apr 18th, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6.     setlocale(LC_ALL, "Russian");
  7.     int sar[20][20];
  8.     int k = 1, a, b;
  9.     cout << "Введите размер масива" << endl;
  10.     cin >> a >> b;
  11.     for (int i = 0; i < a; i++) {
  12.         if ((i + 1) % 2 != 0) {
  13.         for (int j = 0; j < b; j++) {
  14.             sar[i][j] = k++;
  15.         }
  16.         }
  17.         else {
  18.             for (int j = 0; j < b; j++) {
  19.                 sar[i][b - j -1] = k++;
  20.             }
  21.         }
  22.        
  23.     }
  24.  
  25.     cout << "Вывод масива" << endl;
  26.     for (int i = 0; i < a; i++) {
  27.         for (int j = 0; j < b; j++) {
  28.             cout << sar[i][j] << " ";
  29.         }
  30.         cout << endl;
  31.     }
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement