Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Zadacha3._6
- {
- class Program
- {
- static void Main(string[] args)
- {
- int count; //кол. элементов в массиве
- int tmp; //временная переменная
- Console.WriteLine("Введите длину массива: ");
- count = Convert.ToInt32(Console.ReadLine());
- int[] array = new int[count];
- //Заполняем массив
- for (int i = 0; i < count; i++)
- {
- Console.WriteLine("Введите значение эл. ["+(i+1)+"]: ");
- array[i] = Convert.ToInt32(Console.ReadLine());
- }
- Console.WriteLine("Не отcортированный массив: ");
- //Выводим заполненный массив на экран
- for (int i = 0; i < count; i++)
- {
- Console.Write(array[i] + " ");
- }
- //Сортировка массива
- for (int i = 0; i < count; i++)
- {
- for (int j = 0; j < count-1; j++)
- {
- if (array[j] > array[j+1])
- {
- tmp = array[j];
- array[j] = array[j + 1];
- array[j + 1] = tmp;
- }
- }
- }
- Console.WriteLine("\n"+"Отcортированный массив: ");
- //Выводим отсортированный массив
- for (int i = 0; i < count; i++)
- {
- Console.Write(array[i] + " ");
- }
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment