Advertisement
DrDemonik

Untitled

Mar 23rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. using System;
  2. namespace Lesson8
  3. {
  4.     class Program
  5.     {
  6.         static void Main(string[] args)
  7.         {
  8.             int[] ar=new int[0];
  9.             string inputStr;
  10.             do
  11.             {
  12.                 Console.WriteLine("Введите число или слово sum");
  13.                 inputStr = Console.ReadLine();
  14.                 if (!inputStr.Contains("sum"))
  15.                 {            
  16.                     int[] buf = new int[ar.Length];
  17.                     for(int i = 0; i < ar.Length; i++)
  18.                     {
  19.                         buf[i] = ar[i];
  20.                     }
  21.                     ar = new int[buf.Length+1];
  22.                     for (int i = 0; i < buf.Length; i++)
  23.                     {
  24.                         ar[i]=buf[i];
  25.                     }
  26.                     ar[ar.Length - 1] = Convert.ToInt32(inputStr);
  27.                 }
  28.  
  29.             } while (!inputStr.Contains("sum"));
  30.             int sum=0;
  31.             for (int i=0;i<ar.Length;i++)
  32.             {
  33.                 sum += ar[i];
  34.             }
  35.             Console.WriteLine("Сумма всех ячеек: "+sum+"\nСортировка");
  36.            
  37.             int temp;
  38.             for (int i = 0; i < ar.Length - 1; i++)
  39.             {
  40.                 for (int j = i + 1; j < ar.Length; j++)
  41.                 {
  42.                     if (ar[i] > ar[j])
  43.                     {
  44.                         temp = ar[i];
  45.                         ar[i] = ar[j];
  46.                         ar[j] = temp;
  47.                     }
  48.                 }
  49.             }
  50.             for (int i = 0; i < ar.Length; i++)
  51.             {
  52.                 Console.Write(ar[i] + " ");
  53.             }
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement