TheRasVa

[WIP] Задача 8,3

May 16th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4. int matrix[5][5], tmp_mas[5];
  5.  
  6.  
  7. void bubble_sort() //глобальные переменные: mas -- сам массив, mas_size -- размер массива mas
  8. {
  9.     for (int i = 0; i<5; ++i)
  10.     for (int j = i + 1; j<5; ++j)
  11.     if (tmp_mas[j]<tmp_mas[i])swap(tmp_mas[i], tmp_mas[j]);
  12. }
  13.  
  14.  
  15. void matrix_input()
  16. {
  17.     int i = 0, j = 0;
  18.     cout << "Введите матрицу 5x5:\n";
  19.     while (i < 5)
  20.     {
  21.         while (j < 5)
  22.         {
  23.             cin >> matrix[i][j];
  24.             j++;
  25.         }
  26.         j = 0;
  27.         i++;
  28.     }
  29. }
  30.  
  31.  
  32. void matrix_output()
  33. {
  34.     cout << "=-=-=-=-=-=-=-=-=-=-=-\n";
  35.     int i = 0, j = 0;
  36.     while (i < 5)
  37.     {
  38.         while (j < 5)
  39.         {
  40.             cout << matrix[i][j] << ' ';
  41.             j++;
  42.         }
  43.         cout << endl;
  44.         j = 0;
  45.         i++;
  46.     }
  47.     cout << "=-=-=-=-=-=-=-=-=-=-=-\n";
  48. }
  49.  
  50.  
  51. int main()
  52. {
  53.     int i = 0, j = 0;
  54.     setlocale(LC_ALL, "russian");
  55.     system("color 0A");
  56.     matrix_input();
  57.     matrix_output();
  58.     while (i < 5)
  59.     {
  60.         while (j < 5)
  61.         {
  62.             tmp_mas[i] = matrix[i][j];
  63.             bubble_sort();
  64.             matrix[i][j] = tmp_mas[i];
  65.             j++;
  66.         }
  67.         j = 0;
  68.         i++;
  69.     }
  70.     matrix_output();
  71.     system("pause");
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment