Advertisement
allia

класс matrix

Oct 31st, 2020
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. class Matrix
  7. {
  8.   int **arr[100][100];
  9.   public: int m, n;
  10.  
  11.    void sozdanie (int m, int n)
  12.   {
  13.     int **arr = new int*[n];
  14.     for (int i = 0; i < n; i++)
  15.       arr[i] = new int[n];
  16.    
  17.     for (int i = 0; i < n; i++)
  18.       for (int j = 0; j < n; j++)
  19.        arr[i][j] = 0;
  20.  
  21.     matrix(arr, n);
  22.   }
  23.  
  24.  void matrix( int **arr, int n )
  25. {
  26.    for (int j=1; j<n; j++)
  27.       arr[0][j]=j+1+arr[0][j-1];
  28.  
  29.    for (int i=1; i<n; i++)
  30.     for (int j=0; j<n; j++)
  31.      {
  32.        if (j!=n-1)
  33.      arr[i][j]=arr[i-1][j+1]-1;
  34.      else arr[i][j]=arr[i-1][j]+n-i;
  35.      }
  36.  
  37.   print (arr, n, n);
  38. }
  39.  
  40.   void print (int **arr, int m, int n)
  41.   {
  42.     for (int i = 0; i < n; i++)
  43.     {
  44.       for (int j = 0; j < m; j++)
  45.       {
  46.         cout.width(3);
  47.         cout << arr[i][j] << " ";
  48.       }
  49.      cout << endl;
  50.     }
  51.   }
  52.  
  53. };
  54.  
  55. int main()
  56. {
  57.   int x, y;
  58.   cin >> x >> y;
  59.  
  60.   Matrix arr;
  61.   arr.sozdanie(x, y);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement