Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int n, i, j, col;
- int ** matrix, ** newmatrix;
- setlocale(LC_CTYPE, "Russian");
- cout << "Введите размер матрицы: ";
- cin >> n;
- while (n <= 0)
- {
- cout << "Некорректный размер!" << endl;
- cout << "Введите размер матрицы: ";
- cin >> n;
- }
- matrix = new int*[n];
- newmatrix = new int*[n];
- for (i = 0; i < n; i++)
- {
- matrix[i] = new int[n];
- newmatrix[i] = new int[n];
- }
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++)
- {
- matrix[i][j] = rand();
- newmatrix[i][j] = 0;
- }
- cout << "Введите номер столбца: ";
- cin >> col;
- while (col < 0 || col >= n)
- {
- cout << "Некорректный номер!" << endl;
- cout << "Введите номер столбца: ";
- cin >> col;
- }
- for (i = 0; i < n; i++)
- newmatrix[i][i] = matrix[i][col];
- cout << "Случайная матрица:" << endl;
- cout << endl;
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < n; j++)
- cout << matrix[i][j] << "\t";
- cout << endl;
- }
- cout << endl;
- cout << "Полученная матрица:" << endl;
- cout << endl;
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < n; j++)
- cout << newmatrix[i][j] << "\t";
- cout << endl;
- }
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement