elsemTim

3,6

Apr 22nd, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. namespace Zadacha3._6
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int count;                  //кол. элементов в массиве
  11.             int tmp;                    //временная переменная
  12.             Console.WriteLine("Введите длину массива: ");
  13.             count = Convert.ToInt32(Console.ReadLine());
  14.             int[] array = new int[count];
  15.            
  16.             //Заполняем массив
  17.             for (int i = 0; i < count; i++)
  18.             {
  19.                 Console.WriteLine("Введите значение эл. ["+(i+1)+"]: ");
  20.                 array[i] = Convert.ToInt32(Console.ReadLine());
  21.             }
  22.  
  23.             Console.WriteLine("Не отcортированный массив: ");
  24.             //Выводим заполненный массив на экран
  25.             for (int i = 0; i < count; i++)
  26.             {
  27.                 Console.Write(array[i] + " ");
  28.             }
  29.  
  30.             //Сортировка массива
  31.             for (int i = 0; i < count; i++)
  32.             {
  33.                 for (int j = 0; j < count-1; j++)
  34.                 {
  35.                     if (array[j] > array[j+1])
  36.                     {
  37.                         tmp = array[j];
  38.                         array[j] = array[j + 1];
  39.                         array[j + 1] = tmp;
  40.                     }
  41.                 }
  42.             }
  43.             Console.WriteLine("\n"+"Отcортированный массив: ");
  44.             //Выводим отсортированный массив
  45.             for (int i = 0; i < count; i++)
  46.             {
  47.                 Console.Write(array[i] + " ");
  48.             }
  49.             Console.Read();
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment