@David Sylva
1291 / 953 / 51
Регистрация: 17.05.2012
Сообщений: 2,687
|
25.06.2012, 23:12
|
|
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
| #include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main()
{
setlocale(0, "rus"); // русская консоль
srand((unsigned) time(0));
const int N = 5; // размеры
const int M = 5;
int matrix[N][M]; // матрица
int i, j;
int p, q;
for ( i = 0; i < N; i++)
for (j = 0; j < M; j++)
matrix[i][j] = rand() % 10; // заполняем матрицу случайными числами от 0 до 10
for ( i = 0; i < N; i++) // выводим исходную матрицу
for ( j = 0; j < M; j++)
{
if( j % M == 0) // после 5 чисел переход на новую строку
cout << endl;
cout << setw(3) << matrix[i][j];
}
cout << endl;
cout << "Введите номера столбцов" << endl; // незабываем что отсчёт идёт с 0
cin >> p >> q; // то есть столбцы от 0 до 4
cout << endl;
for ( i = 0; i < N; i++)
for ( j = 0; j < M; j++)
{
int temp = matrix[i][p]; // временному элементу присваиваем со элемент П
matrix[i][p] = matrix[i][q]; // элементу П элемет КЬЮ
matrix[i][q] = temp; // КЬЮ временный
}
for ( i = 0; i < N; i++)
for ( j = 0; j < M; j++)
{
if( j % M == 0)
cout << endl;
cout << setw(3) << matrix[i][j]; // выводим изменённую матрицу
}
cout << endl;
system("Pause");
} |
|
1
|