Benjail

3.7

Aug 29th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2.  
  3. namespace IMJunior
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int sum = 0;
  10.             string vvod;
  11.             string menu;
  12.             int tmp;
  13.             Console.WriteLine("Введите строку");                
  14.             vvod = Console.ReadLine();
  15.           string[] array = vvod.Split(' ');
  16.             int[] array2=new int[array.Length];
  17.             for (int i = 0; i < array.Length; i++) //создаю массив int
  18.             {
  19.                 array2[i] = Convert.ToInt32(array[i]);
  20.             }          
  21.             Console.WriteLine("Введите команду: \n1.Sum\n2.Sort");
  22.             menu = Console.ReadLine();            
  23.                 switch (menu)
  24.             {
  25.                 case "1":
  26.                     for (int i = 0; i < array2.Length; i++)
  27.                     {
  28.                         sum += array2[i];
  29.                     }
  30.                     Console.WriteLine("Cумма равна " + sum);
  31.                     break;
  32.                 case "2":
  33.                     for (int i = 0; i < array2.Length; i++)//сортировка методом пузырька
  34.                     {
  35.                         for (int j = 1; j<array2.Length; j++)
  36.                         {
  37.                             if (array2[j] <array2[j-1])
  38.                             {
  39.                                 tmp = array2[j];  
  40.                                 array2[j] = array2[j - 1];  
  41.                                 array2[j - 1] = tmp;
  42.                             }
  43.                         }
  44.                     }
  45.                     for (int i = 0; i < array2.Length; i++)
  46.                     {
  47.                         Console.Write(array2[i]+" ");
  48.                     }
  49.                     break;
  50.                 default:
  51.                     break;
  52.             }            
  53.          
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment