Advertisement
MoonlightFairy

Матрицы-хуятрицы

Jun 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9.     int n, i, j, col;
  10.     int ** matrix, ** newmatrix;
  11.  
  12.     setlocale(LC_CTYPE, "Russian");
  13.     cout << "Введите размер матрицы: ";
  14.     cin >> n;
  15.     while (n <= 0)
  16.     {
  17.         cout << "Некорректный размер!" << endl;
  18.         cout << "Введите размер матрицы: ";
  19.         cin >> n;
  20.     }
  21.  
  22.     matrix = new int*[n];
  23.     newmatrix = new int*[n];
  24.     for (i = 0; i < n; i++)
  25.     {
  26.         matrix[i] = new int[n];
  27.         newmatrix[i] = new int[n];
  28.     }
  29.  
  30.     for (i = 0; i < n; i++)
  31.         for (j = 0; j < n; j++)
  32.         {
  33.             matrix[i][j] = rand();
  34.             newmatrix[i][j] = 0;
  35.         }
  36.  
  37.     cout << "Введите номер столбца: ";
  38.     cin >> col;
  39.     while (col < 0 || col >= n)
  40.     {
  41.         cout << "Некорректный номер!" << endl;
  42.         cout << "Введите номер столбца: ";
  43.         cin >> col;
  44.     }
  45.  
  46.     for (i = 0; i < n; i++)
  47.         newmatrix[i][i] = matrix[i][col];      
  48.  
  49.     cout << "Случайная матрица:" << endl;
  50.     cout << endl;
  51.     for (i = 0; i < n; i++)
  52.     {
  53.         for (j = 0; j < n; j++)
  54.             cout << matrix[i][j] << "\t";
  55.         cout << endl;
  56.     }
  57.     cout << endl;
  58.  
  59.     cout << "Полученная матрица:" << endl;
  60.     cout << endl;
  61.     for (i = 0; i < n; i++)
  62.     {
  63.         for (j = 0; j < n; j++)
  64.             cout << newmatrix[i][j] << "\t";
  65.         cout << endl;
  66.     }
  67.     cout << endl;
  68.  
  69.     system("pause");
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement