Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- const int SIZE = 50;
- void readMatrix(int a[][SIZE], int n, int m);
- void printMatrix(int a[][SIZE], int n, int m);
- void bubbleSort(int arr[], int n);
- void sortRows(int a[][SIZE], int n, int m);
- int main()
- {
- int n, m;
- int matrix[SIZE][SIZE];
- do
- {
- cout << "Enter n: ";
- cin >> n;
- }
- while (n < 0 || n >= SIZE);
- do
- {
- cout << "Enter m: ";
- cin >> m;
- }
- while (m < 0 || m >= SIZE);
- readMatrix(matrix, n, m);
- sortRows(matrix, n, m);
- printMatrix(matrix, n, m);
- return 0;
- }
- void readMatrix(int a[][SIZE], int n, int m)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- cin >> a[i][j];
- }
- }
- }
- void printMatrix(int a[][SIZE], int n, int m)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- cout << setw(4) << a[i][j];
- }
- cout << endl;
- }
- }
- void bubbleSort(int arr[], int n)
- {
- for (int i = 0; i < n - 1; i++)
- {
- for (int j = 0; j < n - i - 1; j++)
- {
- if (arr[j] > arr[j + 1])
- {
- int temp = arr[j];
- arr[j] = arr[j + 1];
- arr[j + 1] = temp;
- }
- }
- }
- }
- void sortRows(int a[][SIZE], int n, int m)
- {
- for (int i = 0; i < n; i++)
- {
- bubbleSort(a[i], m);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement