Advertisement
STANAANDREY

PATTERN

Apr 7th, 2022
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define n 9
  4. int a[n][n];
  5.  
  6. int main() {
  7.     for (int i = 0; i < n; i++)
  8.         for (int j = 0; j < n; j++)
  9.             a[i][j] = -1;
  10.  
  11.     for (int i = 0; i < n; i++)
  12.         for (int j = 0; j < n; j++)
  13.             if (i == j || n - i - 1 == j) a[i][j] = 0;
  14.             else if (j < n - i - 1) a[i][j] = i + j;
  15.             else a[i][j] = a[i][j - 1] + 1;
  16.  
  17.     for (int i = 0; i < n; i++) {
  18.         for (int j = 0; j < n; j++) {
  19.             cout << a[i][j] << ' ';
  20.         }
  21.         cout << endl;
  22.     }
  23.  
  24.     return 0;
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement