Dr_Max_Experience

New task 7

Mar 18th, 2022 (edited)
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace HW
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int arrayLength = 10;
  14.             int arrayValues = 25;
  15.             int temporaryValue;
  16.             int[] array = new int[arrayLength];
  17.             Random random = new Random();
  18.  
  19.             for (int i = 0; i < array.Length; i++)
  20.             {
  21.                 array[i] = random.Next(arrayValues);
  22.                 Console.Write(array[i] + " ");
  23.             }
  24.  
  25.             for (int j = 0; j < array.Length; j++)
  26.             {
  27.                 for (int i = 0; i < array.Length - 1; i++)
  28.                 {
  29.                     int index = i;
  30.  
  31.                     if (array[index] > array[++index])
  32.                     {
  33.                         temporaryValue = array[index];
  34.                         array[index] = array[--index];
  35.                         array[index] = temporaryValue;
  36.                     }
  37.                 }
  38.             }
  39.  
  40.             Console.WriteLine();
  41.  
  42.             for (int i = 0; i < array.Length; i++)
  43.             {
  44.                 Console.Write(array[i] + " ");
  45.             }
  46.         }
  47.     }
  48. }
Add Comment
Please, Sign In to add comment