Advertisement
Garey

Find Min By Row

Nov 7th, 2017
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. //////////////////////////////////////////////////////////////////////////////////////
  2. // Задачата намира минималният елемент за всеки ред и го изписва на краят на реда. //
  3. ////////////////////////////////////////////////////////////////////////////////////
  4. #include <iostream>
  5. #include <ctime>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.   srand(time(0));
  11.   int matrix[2][7];
  12.   int min_by_row[2];
  13.  
  14.   for (size_t i = 0; i < 2; i++) {
  15.     for (size_t j = 0; j < 7; j++) {
  16.         matrix[i][j] = rand() % (9 - 1);
  17.     }
  18.   }
  19.  
  20.   for (size_t i = 0; i < 2; i++) {
  21.     min_by_row[i] = matrix[i][0];
  22.     for (size_t j = 0; j < 7; j++) {
  23.         cout << matrix[i][j] << "   ";
  24.         if(min_by_row[i] > matrix[i][j])
  25.           min_by_row[i] = matrix[i][j];
  26.     }
  27.     cout << min_by_row[i] << endl;
  28.   }
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement