Advertisement
totobac

Untitled

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