Advertisement
totobac

Untitled

Jan 26th, 2021
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. const int MAX_SIZE = 10;
  5.  
  6. int main()
  7. {
  8.     int n;
  9.     cout << "Enter n between 4 and 10: ";
  10.     cin >> n;
  11.     int* array = new int[n];
  12.     for (size_t i = 0; i < n ; i++)
  13.     {
  14.         cin >> array[i];
  15.     }
  16.  
  17.     double matrix[MAX_SIZE][MAX_SIZE];
  18.  
  19.     int r = 0;
  20.     for (size_t row = 0; row < n; row++)
  21.     {
  22.         for (size_t col = 0; col < n ; col++)
  23.         {
  24.             if (row == col) {
  25.                 matrix[row][col] = array[r];
  26.                 r++;
  27.             }
  28.             if (row > col)
  29.             {
  30.                 matrix[row][col] = row + matrix[row - 1][col];
  31.             }
  32.  
  33.         }
  34.     }
  35.  
  36.     for (int row = n; row >= 0; row--)
  37.     {
  38.         for (size_t col = 0; col < n; col++)
  39.         {
  40.             if (row < col)
  41.             {
  42.                 matrix[row][col] =  (matrix[row][col - 1] + matrix[row + 1][col]) / 2.0;
  43.             }
  44.         }
  45.     }
  46.  
  47.     for (size_t i = 0; i < n; i++)
  48.     {
  49.         cout << endl;
  50.         for (size_t j = 0; j < n ; j++)
  51.         {
  52.             cout<< matrix[i][j]<< " ";
  53.         }
  54.     }
  55.  
  56.     delete[] array;
  57.  
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement