Anonim_999

2.4

Dec 22nd, 2022
774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp27
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.WriteLine("Введите 2 числа: ");
  10.             string aInput = Console.ReadLine();
  11.             string bInput = Console.ReadLine();
  12.             string cInput;
  13.             int a, b, c;
  14.  
  15.             if (int.TryParse(aInput, out a) && int.TryParse(bInput,out b))
  16.             {
  17.                 MinMax(ref a, ref b);
  18.                 Console.WriteLine($"{a} {b}");
  19.             }
  20.             else
  21.             {
  22.                 Console.WriteLine("Ошибка ввода!");
  23.             }
  24.  
  25.             Console.WriteLine("Введите 3 числа: ");
  26.             aInput = Console.ReadLine();
  27.             bInput = Console.ReadLine();
  28.             cInput = Console.ReadLine();
  29.  
  30.             if (int.TryParse(aInput, out a)
  31.                 && int.TryParse(bInput, out b)
  32.                 && int.TryParse(cInput, out c))
  33.             {
  34.                 MinMax(ref a, ref b, ref c);
  35.                 Console.WriteLine($"{a} {b} {c}");
  36.             }
  37.         }
  38.  
  39.         private static void MinMax(ref int a, ref int b)
  40.         {
  41.             int temp = 0;
  42.  
  43.             if (a < b)
  44.             {
  45.                 temp = a;
  46.                 a = b;
  47.                 b = temp;
  48.             }
  49.         }
  50.  
  51.         private static void MinMax(ref int a, ref int b, ref int c)
  52.         {
  53.             int temp = 0;
  54.  
  55.             if (a < b)
  56.             {
  57.                 temp = a;
  58.                 a = b;
  59.                 b = temp;
  60.             }
  61.  
  62.             if (a < c)
  63.             {
  64.                 temp = a;
  65.                 a = c;
  66.                 c = temp;
  67.             }
  68.  
  69.             if (b < c)
  70.             {
  71.                 temp = c;
  72.                 c = b;
  73.                 b = temp;
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment