Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.64 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 ConsoleApp19
  8. {
  9.     class Program
  10.     {
  11.         private static int[] mas;
  12.         private static int N;
  13.         private static Random r = new Random();
  14.  
  15.         static int a = 0;
  16.         static int b = 0;
  17.  
  18.         static void Sort1Up()
  19.         {
  20.             int temp;
  21.             for (int i = 0; i < N; i++) // по выбору
  22.             {
  23.                 for (int j = 0; j < N; j++)
  24.                 {
  25.                    
  26.                     if (mas[i] > mas[j])
  27.                     {
  28.  
  29.                         temp = mas[i];
  30.                         mas[i] = mas[j];
  31.                         mas[j] = temp;
  32.                         //a++;
  33.                     }
  34.                 }
  35.             }
  36.         }
  37.  
  38.         static void Sort2Up()
  39.         {
  40.             int temp;
  41.             for (int i = 0; i < N; i++) // пузырьковый
  42.             {
  43.                 for (int j = i + 1; j < N; j++)
  44.                 {
  45.                    
  46.                     if (mas[i] > mas[j])
  47.                     {
  48.  
  49.                         temp = mas[i];
  50.                         mas[i] = mas[j];
  51.                         mas[j] = temp;
  52.                         //b++;
  53.                     }
  54.                 }
  55.             }
  56.         }
  57.  
  58.  
  59.         static void PrintMatrix()
  60.         {
  61.             for (int i = 0; i < N; i++)
  62.             {
  63.                 Console.WriteLine(mas[i].ToString());
  64.             }
  65.         }
  66.         static void FullRandom()
  67.         {
  68.  
  69.             for (int i = 0; i < N; i++)
  70.             {
  71.                 mas[i] = r.Next(0, 100);
  72.             }
  73.         }
  74.         static int MaxArray()
  75.         {
  76.             int max = mas[0];
  77.             for (int i = 0; i < N; i++)
  78.             {
  79.                 if (mas[i] > max)
  80.                 {
  81.                     max = mas[i];
  82.                 }
  83.             }
  84.             return max;
  85.         }
  86.  
  87.         static void Main(string[] args)
  88.         {
  89.             N = int.Parse(Console.ReadLine());
  90.             mas = new int[N];
  91.             Console.WriteLine();
  92.             FullRandom();
  93.             Console.WriteLine(MaxArray() + " Максимальное число");
  94.             Sort1Up();
  95.             PrintMatrix();
  96.             Console.WriteLine();
  97.  
  98.             mas = new int[N];
  99.             FullRandom();
  100.             Console.WriteLine(MaxArray() + " Максимальное число");
  101.             Sort2Up();
  102.             PrintMatrix();
  103.  
  104.             //Console.WriteLine(a + " " + b);
  105.  
  106.             Console.ReadLine();
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement