Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Rjadkii.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- int array[5][5];//creating array
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 5; j++)
- {
- array[i][j] = rand() % 10;//input random digits into array
- }
- }
- //sorting every row in array from min to max
- for (int x = 0; x < 5; x++)
- {
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 5 - 1; j++)
- {
- if (array[i][j] > array[i][j + 1])
- {
- int tmp = array[i][j];
- array[i][j] = array[i][j + 1];
- array[i][j + 1] = tmp;
- }
- }
- }
- }
- //showing sorted array
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 5; j++)
- {
- cout << array[i][j] << " ";
- }
- cout << endl;
- }
- }
Add Comment
Please, Sign In to add comment