Azdws

Untitled

Mar 11th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. void matrixOperations(int row, int column) {
  6.  
  7. /*---------- Çàïîëíåíèå ìàòðèöû ñëó÷àéíìè ÷èñëàìè -------------*/ 
  8.     cout << endl;
  9.     cout << "Ïîëó÷åííàÿ ìàòðèöà:\n";
  10.     int matrix[row][column];  
  11.             for (int i = 0; i < row; i++) {
  12.                 for (int j = 0; j < column; j++) {
  13.                 matrix[i][j] = rand()%350;
  14.                 cout << matrix[i][j] << " ";   
  15.                 }
  16.             cout << endl;
  17.     }
  18. /*-------------------------------------------------------------*/
  19.  
  20. cout << endl;
  21.  
  22. /*------------ Ïîèñê ìàêñèìóìà/ìèíèìóìà ìàòðèöû ---------------*/ 
  23.     int min, max ;
  24.     int minstr, minstl, maxstr, maxstl;
  25.     min = matrix[0][0]; max = matrix[0][0];
  26.     for (int i = 0; i < row; i++) {  
  27.         for (int j = 0; j < column; j++) {
  28.             if ( matrix[i][j] < min)
  29.             {
  30.                
  31.             min = matrix[i][j];
  32.             minstr = i;
  33.             minstl = j;
  34.            
  35.             } else
  36.            
  37.                 if ( matrix[i][j] > max)
  38.                 {
  39.                 max = matrix[i][j];
  40.                 maxstr = i;
  41.                 maxstl = j;
  42.                 }
  43.                
  44.         }
  45.     }  
  46.    
  47.     cout << endl;
  48.     cout << "Ìèíèìàëüíîå çíà÷åíèå: " << min;
  49.     cout << " [" << minstr+1 << "]" << "[" << minstl+1 << "]\n";
  50.     cout << "Ìàêñèìàëüíîå çíà÷åíèå: " << max;
  51.     cout << " [" << maxstr+1 << "]" << "[" << maxstl+1 << "]\n";
  52. /*-----------------------------------------------------------------*/  
  53.  
  54.     cout << endl;
  55.    
  56. /*----------------- Ñóììû êàæäûõ ñòðîê ìàòðèöû ------------------*/ 
  57.     for(int i = 0; i < row; i++){
  58.     int rowSum = 0;
  59.     for(int j = 0; j < column; j++) {
  60.     rowSum += matrix[i][j];
  61.     }
  62.     cout << " - [Ñóììà] " << i+1 <<" ñòðîêà: "; cout << rowSum << '\n';
  63.     }    
  64.     cout << endl;
  65. /*-----------------------------------------------------------------*/  
  66.  
  67. /*----------------- Ñóììû êàæäûõ ñòîëáöîâ ìàòðèöû ------------------*/   
  68.     for(int j = 0; j < column; j++){
  69.     int columnSum = 0;
  70.     for(int i = 0; i < row; i++) {
  71.     columnSum += matrix[i][j];
  72.     }
  73.     cout << " - [Ñóììà] " << j+1 <<" ñòîëáöà: "; cout << columnSum << '\n';
  74.     }        
  75.     cout << endl;
  76. /*-----------------------------------------------------------------*/  
  77.  
  78. cout << "\n";  
  79.    
  80. /*------------ Ñîðòèðîâêà ñòðîê ìàòðèöû  ---------------*/   
  81.     cout << "Îòñîðòèðîâàííûå ñòðîêè ìàòðèöû:\n";
  82.        for(int i = 0; i < row; i++) {
  83.             for(int j = 0; j < column; j++) {
  84.                 int index = j;
  85.                 int minElement = matrix[i][j];
  86.                 for(int z = j; z < column; z++)
  87.                     {
  88.                         if(minElement < matrix[i][z])
  89.                         {
  90.                             index=z;
  91.                             minElement=matrix[i][z];
  92.                         }
  93.                     }
  94.                 swap(matrix[i][j],matrix[i][index]);
  95.                 cout << matrix[i][j] << " ";
  96.             }
  97.             cout << endl;
  98.         }
  99. /*---------------------------------------------------------*/      
  100. }
  101.  
  102. int main() {
  103. int row, column;
  104.     setlocale(0,"Russian");
  105.  
  106.     cout << "Êîë-âî ñòðîê: "; cin >> row;
  107.     cout << "Êîë-âî ñòîëáöîâ: "; cin >> column;
  108.    
  109.     int *n = new int[row];
  110.     int *m = new int [column];
  111.        
  112.     matrixOperations(row,column);
  113.  
  114.     delete [] n;
  115.     delete [] m;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment