Matrix62. Дана матрица размера M × N и целое число K (1 ≤ K ≤ N). Удалить столбец матрицы с номером K.
>Решение Pascal
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 | program Matrix62; type matrix = array [1..10,1..10] of integer; var a:matrix; K, M, N, i, j:Integer; procedure DelMatrixColumn(var mat:matrix; X:Integer); var i:integer; begin N:=N-1; for j:=X to N do for i:=1 to M do mat[i,j]:=mat[i,j+1]; end; begin Write('N: '); Readln(N); Write('M: '); Readln(M); Write('K: '); Readln(K); for i:=1 to M do begin writeln(i,': '); for j:=1 to N do begin Write(j,' : '); Read(a[i,j]); end; end; DelMatrixColumn(a,K); for i:=1 to M do begin for j:=1 to N do begin Write(' : ',a[i,j]); end; writeln(' : '); end; end. |
Решение 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 | # include <iostream> # include <windows.h> # include <cmath> # include <iomanip> # include <fstream> # include "IOMatrix.h" using namespace std; int main () { SetConsoleCP(1251); SetConsoleOutputCP(1251); double matr[RMAX][CMAX]; int nr, nc; input (matr,"Matrix62.txt",nr,nc); output (matr,nr,nc); cout << endl; int K; cout << "Введите число K:"<< endl; cin >> K; for (int col = K; col < nc; ++col) { for (int row = 0; row < nr; ++row) { matr[row][col-1] = matr[row][col]; } cout << endl; } cout << "Преобразованная матрица" << endl; output (matr,nr,--nc); system ("pause"); return 0; } |
IOMatrix.h
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 <fstream> using namespace std; const int RMAX=100; const int CMAX=100; void input(double a[][CMAX],const char* name, int& nr, int& nc) { ifstream in (name); //cout << "Введите количество строк и столбцов матрицы: "; //cin >> nr >> nc; for (int row = 0; row < nr; ++row) { for (int col = 0; col < nc; ++col) { in >> a[row][col]; } } in.close(); } void output(const double a[][CMAX],int nr, int nc) { for (int row = 0; row < nr; ++row) { for (int col = 0; col < nc; ++col) { cout << '\t' << a[row][col] << " "; } cout << endl; } } void input(int a[][CMAX],const char* name, int& nr, int& nc) { ifstream in (name); //cout << "Введите количество строк и столбцов матрицы: "; //cin >> nr >> nc; for (int row = 0; row < nr; ++row) { for (int col = 0; col < nc; ++col) { in >> a[row][col]; } } in.close(); } void output(const int a[][CMAX],int nr, int nc) { for (int row = 0; row < nr; ++row) { for (int col = 0; col < nc; ++col) { cout << '\t' << a[row][col] << " "; } cout << endl; } } |
Matrix62.txt
1 2 3 4 | 4 6 3 7 1 3 6 4 2 9 -1 2 -6 -2 0 4 55 13 66 2 |