Advertisement
kxcoze

lab8_16_1

Mar 26th, 2020
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3.    
  4. using namespace std;    
  5.  
  6. const int n = 5;
  7.  
  8. void printMat(int a[][n]) {
  9.     for (int i = 0; i < n; i++) {
  10.         cout << '(';
  11.         for (int j = 0; j < n; j++) {
  12.             if (j != n-1)
  13.                 cout << a[i][j] << '\t';
  14.             else
  15.                 cout << a[i][j];
  16.         }  
  17.         cout << ")\n";  
  18.     }  
  19. }
  20.  
  21. int main() {    
  22.     setlocale(LC_ALL, "Rus");
  23.     cout << "Матрица " << n << 'x' << n << '\n';
  24.     int mat[n][n];
  25.     for (int i = 0; i < n; i++)
  26.         mat[i][0] = mat[0][i] = 1;
  27.  
  28.     for (int i = 1; i < n; i++) {
  29.         for (int j = 1; j < n; j++) {
  30.             mat[i][j] = mat[i-1][j] + mat[i][j-1];
  31.         }  
  32.     }
  33.  
  34.     printMat(mat);
  35.     system("pause");
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement