fork(2) download
  1. #include <iostream>
  2. #include <cstdlib>
  3. int main() {
  4. using namespace std;
  5. const int SIZE1 = 10;
  6. int mass[SIZE1] = { 1 + rand() % 9 };
  7. for (int i = 0; i < SIZE1; i++) {
  8. mass[i] = { 1 + rand() % 9 }; //инициализируем массив случайными числами
  9. cout << mass[i] << " "; // выводим массив
  10. }
  11. cout << endl;
  12. for (int j = 0; j < SIZE1; j++) {
  13. for (int i = 0; i < SIZE1-1; i++) {
  14. if (mass[i] > mass[i + 1])
  15. swap(mass[i], mass[i + 1]); //Функция swap меняет местами значения
  16. }
  17. }
  18. for (int j = SIZE1 - 1; j >= 0; j--)
  19. cout << mass[j] << " "; // Выводим массив в обратном порядке ( с 9 до 0 включительно )
  20. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
8 1 8 6 8 2 4 7 2 6 
8 8 8 7 6 6 4 2 2 1