Created
December 7, 2015 19:54
-
-
Save zhuharev/11661ac28cf16a36317c to your computer and use it in GitHub Desktop.
lab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace ConsoleApplication22 | |
{ | |
class Test | |
{ | |
static void sort(int[] arr) | |
{ | |
int temp = 0; | |
for (int write = 0; write < arr.Length; write++) { | |
for (int sort = 0; sort < arr.Length - 1; sort++) { | |
if (arr[sort] > arr[sort + 1]) { | |
temp = arr[sort + 1]; | |
arr[sort + 1] = arr[sort]; | |
arr[sort] = temp; | |
} | |
} | |
} | |
} | |
static void Main(string[] args) | |
{ | |
// Длинна массива | |
int len = 30; | |
// Номер по журналу | |
int journalNum = 9; | |
// Массив | |
int[] arr = new int[len]; | |
// Вспомогательная переменная. Если true, значит есть элемент, соответс- | |
// твующий номеру по журналу | |
bool has = false; | |
// заполнение массив случайными числами | |
Random rd = new Random(); | |
for (int i = 0; i < arr.Length; ++i) | |
{ | |
arr[i] = rd.Next(1, 100); | |
if ( arr[i] == journalNum) | |
{ | |
has = true; | |
} | |
} | |
System.Console.WriteLine("Массив перед сортировкой:"); | |
foreach (double x in arr) | |
{ | |
System.Console.Write(x + " "); | |
} | |
Console.WriteLine(); | |
// Сортировка | |
sort(arr); | |
System.Console.WriteLine("Массив после сортировки:"); | |
foreach (double x in arr) | |
{ | |
System.Console.Write(x + " "); | |
} | |
if (has) | |
{ | |
Console.WriteLine("\nВ массиве есть элемент со значением {0}", journalNum); | |
} else { | |
Console.WriteLine("\nВ массиве нет элемента со значением {0}", journalNum); | |
} | |
System.Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment