Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- void matrixOperations(int row, int column) {
- /*---------- Çàïîëíåíèå ìàòðèöû ñëó÷àéíìè ÷èñëàìè -------------*/
- cout << endl;
- cout << "Ïîëó÷åííàÿ ìàòðèöà:\n";
- int matrix[row][column];
- for (int i = 0; i < row; i++) {
- for (int j = 0; j < column; j++) {
- matrix[i][j] = rand()%350;
- cout << matrix[i][j] << " ";
- }
- cout << endl;
- }
- /*-------------------------------------------------------------*/
- cout << endl;
- /*------------ Ïîèñê ìàêñèìóìà/ìèíèìóìà ìàòðèöû ---------------*/
- int min, max ;
- int minstr, minstl, maxstr, maxstl;
- min = matrix[0][0]; max = matrix[0][0];
- for (int i = 0; i < row; i++) {
- for (int j = 0; j < column; j++) {
- if ( matrix[i][j] < min)
- {
- min = matrix[i][j];
- minstr = i;
- minstl = j;
- } else
- if ( matrix[i][j] > max)
- {
- max = matrix[i][j];
- maxstr = i;
- maxstl = j;
- }
- }
- }
- cout << endl;
- cout << "Ìèíèìàëüíîå çíà÷åíèå: " << min;
- cout << " [" << minstr+1 << "]" << "[" << minstl+1 << "]\n";
- cout << "Ìàêñèìàëüíîå çíà÷åíèå: " << max;
- cout << " [" << maxstr+1 << "]" << "[" << maxstl+1 << "]\n";
- /*-----------------------------------------------------------------*/
- cout << endl;
- /*----------------- Ñóììû êàæäûõ ñòðîê ìàòðèöû ------------------*/
- for(int i = 0; i < row; i++){
- int rowSum = 0;
- for(int j = 0; j < column; j++) {
- rowSum += matrix[i][j];
- }
- cout << " - [Ñóììà] " << i+1 <<" ñòðîêà: "; cout << rowSum << '\n';
- }
- cout << endl;
- /*-----------------------------------------------------------------*/
- /*----------------- Ñóììû êàæäûõ ñòîëáöîâ ìàòðèöû ------------------*/
- for(int j = 0; j < column; j++){
- int columnSum = 0;
- for(int i = 0; i < row; i++) {
- columnSum += matrix[i][j];
- }
- cout << " - [Ñóììà] " << j+1 <<" ñòîëáöà: "; cout << columnSum << '\n';
- }
- cout << endl;
- /*-----------------------------------------------------------------*/
- cout << "\n";
- /*------------ Ñîðòèðîâêà ñòðîê ìàòðèöû ---------------*/
- cout << "Îòñîðòèðîâàííûå ñòðîêè ìàòðèöû:\n";
- for(int i = 0; i < row; i++) {
- for(int j = 0; j < column; j++) {
- int index = j;
- int minElement = matrix[i][j];
- for(int z = j; z < column; z++)
- {
- if(minElement < matrix[i][z])
- {
- index=z;
- minElement=matrix[i][z];
- }
- }
- swap(matrix[i][j],matrix[i][index]);
- cout << matrix[i][j] << " ";
- }
- cout << endl;
- }
- /*---------------------------------------------------------*/
- }
- int main() {
- int row, column;
- setlocale(0,"Russian");
- cout << "Êîë-âî ñòðîê: "; cin >> row;
- cout << "Êîë-âî ñòîëáöîâ: "; cin >> column;
- int *n = new int[row];
- int *m = new int [column];
- matrixOperations(row,column);
- delete [] n;
- delete [] m;
- }
Advertisement
Add Comment
Please, Sign In to add comment