Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- const int m = 10, n = 10;
- int tab[m][n];
- int sum = m * n;
- void Rand_10x10_fill(int start, int finish)
- {
- srand(time(NULL));
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- tab[i][j] = rand() % (finish - start + 1) + start;
- }
- }
- }
- void sort_2d_matrix(int MyArray[m][n])
- {
- for (int ir = 0; ir < m; ir++)
- {
- for (int ic = 0; ic < m; ic++)
- {
- for (int jr = 0; jr < n; jr++)
- {
- for (int jc = 0; jc < n; jc++)
- {
- if (MyArray[ir][jr] > MyArray[ic][jc])
- {
- int temp = MyArray[ir][jr];
- MyArray[ir][jr] = MyArray[ic][jc];
- MyArray[ic][jc] = temp;
- }
- }
- }
- }
- }
- }
- void display_matrix() {
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- cout << " " << tab[i][j];
- }
- cout << endl;
- }
- }
- int main()
- {
- //cin >> m >> n;
- //srand(time(NULL));
- Rand_10x10_fill(NULL, sum);
- cout << endl;
- cout << "macierz randomowa \n\n";
- display_matrix();
- cout << endl;
- cout << "macierz odsortowana \n\n";
- sort_2d_matrix(tab);
- display_matrix();
- cout << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement