Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace homework
- {
- class Program
- {
- static void Main(string[] args)
- {
- float[] numbers = new float[0];
- string cinCommand="";
- while (cinCommand!="sum")
- {
- Console.Clear();
- Console.SetCursorPosition(0, 1);
- Console.WriteLine("Вводите числа. Если хотите суммировать их, введите \"sum\". Для сортировки введите \"sort\". Для выхода нажмите \"Enter\"");
- if (numbers.Length > 0)
- {
- Console.Write("Цифры в массиве: ");
- for (int i = 0; i < numbers.Length; i++)
- Console.Write(numbers[i] + ", ");
- }
- Console.SetCursorPosition(0, 0);
- cinCommand = Console.ReadLine();
- switch (cinCommand)
- {
- case "sum":
- float summ=0;
- for(int i=0;i<numbers.Length;i++)
- {
- summ += numbers[i];
- }
- Console.SetCursorPosition(0, 3);
- Console.WriteLine("Сумма = "+summ);
- break;
- case "sort":
- for (int j = 0; j < numbers.Length - 1; j++)
- {
- for (int k = j + 1; k < numbers.Length; k++)
- {
- if (numbers[j] < numbers[k])
- {
- float temp = numbers[k];
- numbers[k] = numbers[j];
- numbers[j] = temp;
- }
- }
- }
- break;
- case "":
- Console.SetCursorPosition(0, 3);
- return;
- default:
- bool flag = true;
- for (int i =0; i<cinCommand.Length;i++)
- {
- if (cinCommand[i] < '0' || cinCommand[i] > '9')
- {
- flag = false;
- Console.SetCursorPosition(0, 2);
- Console.WriteLine("Введено некорректное число");
- Console.ReadKey();
- }
- }
- if (!flag) break;
- float[] mas = new float[numbers.Length+1];
- for (int i =0; i< numbers.Length;i++)
- {
- mas[i] = numbers[i];
- }
- mas[mas.Length-1] = float.Parse(cinCommand);
- numbers = mas;
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement