Skip to content

Instantly share code, notes, and snippets.

@Ana19997
Created September 27, 2021 17:40
Show Gist options
  • Save Ana19997/d78e66ebfab6b55e72a2fbf208826d6d to your computer and use it in GitHub Desktop.
Save Ana19997/d78e66ebfab6b55e72a2fbf208826d6d to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace сум
{
class Program
{
static void Main(string[] args)
{
int sum = 0;
string count = "sum";
string exit = "exit";
string userInput = "";
int n;
Console.WriteLine("Введите размер массива: ");
n = Convert.ToInt16(Console.ReadLine());
int[] Data = new int[n];
int i = 0;
while (i < n)
{
Console.WriteLine("Введите элемент массива");
Data[i] = int.Parse(Console.ReadLine());
Console.WriteLine();
i++;
}
for (i = 0; i < n; i = i + 1)
Console.WriteLine("Элемент[" + i + "]: " + Data[i]);
Console.ReadKey();
while(userInput != "sum")
{
userInput = Console.ReadLine();
for (i = 0; i < Data.GetLength(0); i++)
{
sum += Data[i];
}
Console.WriteLine("Сумма элементов: " + sum + " \n");
if (userInput == exit)
{
Console.WriteLine("Всего хорошего!");
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment