Synchronization of old projects
Part1
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
namespace Lesson
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Print(int[] arr)
|
||||
{
|
||||
for (int i = 0; i < arr.Length; i++)
|
||||
{
|
||||
Console.Write(arr[i] + " ");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] arr = new int[20];
|
||||
Random r = new Random();
|
||||
for (int i = 0;i < arr.Length; i++)
|
||||
{
|
||||
arr[i] = r.Next(1,101);
|
||||
}
|
||||
Print(arr);
|
||||
|
||||
|
||||
for (int m = 0; m < arr.Length; m++)
|
||||
{
|
||||
int index = 0;
|
||||
for (int n = 1; n < arr.Length - m; n++)
|
||||
{
|
||||
if (arr[index] < arr[n])
|
||||
{
|
||||
index = n;
|
||||
}
|
||||
}
|
||||
if (index != arr.Length - 1 - m)
|
||||
{
|
||||
int temp = arr[index];
|
||||
arr[index] = arr[arr.Length - 1 - m];
|
||||
arr[arr.Length - 1 - m] = temp;
|
||||
}
|
||||
}
|
||||
Print(arr);
|
||||
|
||||
for (int m = 0; m < arr.Length; m++)
|
||||
{
|
||||
int index = 0;
|
||||
for (int n = 1; n < arr.Length - m; n++)
|
||||
{
|
||||
if (arr[index] > arr[n])
|
||||
{
|
||||
index = n;
|
||||
}
|
||||
}
|
||||
if (index != arr.Length - 1 - m)
|
||||
{
|
||||
int temp = arr[index];
|
||||
arr[index] = arr[arr.Length - 1 - m];
|
||||
arr[arr.Length - 1 - m] = temp;
|
||||
}
|
||||
}
|
||||
Print(arr);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user