Advertisement
Guest User

ne esh menya

a guest
Oct 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication221018
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Console.WriteLine("Выберите задание");
  13.             int choose = Convert.ToInt32(Console.ReadLine());
  14.             if (choose == 1)
  15.             {
  16.                 Console.WriteLine("Введите число");
  17.                 int num = Convert.ToInt32(Console.ReadLine());
  18.                 int[] num2 = num.ToString().Select(digit => int.Parse(digit.ToString())).ToArray();
  19.                 Array.Sort(num2);
  20.                 Array.Reverse(num2);
  21.                 Console.WriteLine("Наибольшая цифра числа: {0}", num2[0]);
  22.                 Console.ReadKey();
  23.             }
  24.             if (choose == 2)
  25.             {
  26.                 Console.WriteLine("Введите число");
  27.                 int num = Convert.ToInt32(Console.ReadLine());
  28.                 int[] num2 = num.ToString().Select(digit => int.Parse(digit.ToString())).ToArray();
  29.                 int chet = 0;
  30.                 int nechet = 0;
  31.                 int i = 0;
  32.                 while (num2.Length != chet + nechet)
  33.                 {
  34.                     if (num2[i] % 2 == 0)
  35.                     {
  36.                         chet++;
  37.                     }
  38.                     else
  39.                     {
  40.                         nechet++;
  41.                     }
  42.                     i++;
  43.                 }
  44.                 Console.WriteLine("Чётные: {0} Нечётные: {1}", chet, nechet);
  45.                 Console.ReadKey();
  46.             }
  47.             if (choose == 3)
  48.             {
  49.                 Console.WriteLine("Введите число");
  50.                 int num = Convert.ToInt32(Console.ReadLine());
  51.                 int[] num2 = num.ToString().Select(digit => int.Parse(digit.ToString())).ToArray();
  52.                 int num2Final = 0;
  53.                 Array.Reverse(num2);
  54.                 for (int i = 0; i < num2.Length; i++)
  55.                 {
  56.                     num2Final += num2[i] * Convert.ToInt32(Math.Pow(10, num2.Length - i - 1));
  57.                 }
  58.                 Console.WriteLine("Перевёрнутое число: {0}", num2Final);
  59.                 Console.ReadKey();
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement