Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _3._3
- {
- class Program
- {
- static void Main(string[] args)
- {
- string userInput;
- int[] array = new int[0];
- Console.WriteLine("Если хотите посчитать сумму введеных вами чисел, введите \"sum\"");
- Console.WriteLine("\nВведите данные: ");
- while ((userInput = Console.ReadLine()) != "sum")
- {
- int[] tempArray = new int[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- tempArray[tempArray.Length - 1] = Convert.ToInt32(userInput);
- array = tempArray;
- }
- int sum = 0;
- for (int i = 0; i < array.Length; i++)
- {
- sum += array[i];
- }
- Console.WriteLine("Сумма введеных чисел равна " + sum);
- Console.WriteLine("\nЕсли желаете отсортировать числа в порядке убывания, введите \"sort\"");
- userInput = Console.ReadLine();
- if (userInput == "sort")
- {
- int temp;
- for (int i = 0; i < array.Length - 1; i++)
- {
- for (int j = i + 1; j < array.Length; j++)
- {
- if (array[i] < array[j])
- {
- temp = array[i];
- array[i] = array[j];
- array[j] = temp;
- }
- }
- }
- Console.WriteLine("Вывод отсортированного массива");
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i] > 0)
- {
- Console.Write(array[i] + " ");
- }
- }
- }
- else
- {
- Console.WriteLine("\nНеизвестная команда!");
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment