Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace IMJunior
- {
- class Program
- {
- static void Main(string[] args)
- {
- int sum = 0;
- string vvod;
- string menu;
- int tmp;
- Console.WriteLine("Введите строку");
- vvod = Console.ReadLine();
- string[] array = vvod.Split(' ');
- int[] array2=new int[array.Length];
- for (int i = 0; i < array.Length; i++) //создаю массив int
- {
- array2[i] = Convert.ToInt32(array[i]);
- }
- Console.WriteLine("Введите команду: \n1.Sum\n2.Sort");
- menu = Console.ReadLine();
- switch (menu)
- {
- case "1":
- for (int i = 0; i < array2.Length; i++)
- {
- sum += array2[i];
- }
- Console.WriteLine("Cумма равна " + sum);
- break;
- case "2":
- for (int i = 0; i < array2.Length; i++)//сортировка методом пузырька
- {
- for (int j = 1; j<array2.Length; j++)
- {
- if (array2[j] <array2[j-1])
- {
- tmp = array2[j];
- array2[j] = array2[j - 1];
- array2[j - 1] = tmp;
- }
- }
- }
- for (int i = 0; i < array2.Length; i++)
- {
- Console.Write(array2[i]+" ");
- }
- break;
- default:
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment