Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp3
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Выберите программу\n\n0 - ");
- int[] mass;
- int sumResult = 0;
- Random random = new Random();
- int programm = Convert.ToInt32(Console.ReadLine());
- switch (programm)
- {
- case 1:
- mass = new int[100];
- for (int i = 0; i < mass.Length; i++)
- {
- mass[i] = random.Next(-5, 5);
- if (mass[i] >= 0)
- {
- sumResult += mass[i];
- }
- Console.WriteLine($"Элемент массива {i} = {mass[i]}");
- }
- Console.WriteLine($"Сумма всех положительных элементов = {sumResult}");
- break;
- case 2:
- Console.Write("Введите размер массива = ");
- mass = new int[Convert.ToInt32(Console.ReadLine())];
- for(int i = 0; i < mass.Length; i++)//Вводим элементы
- {
- Console.Write($"Введите элемент массива под индексом {i} = ");
- mass[i] = Convert.ToInt32(Console.ReadLine());
- }
- for(int i = 1; i < mass.Length; i++)
- {
- sumResult += mass[i];
- Console.WriteLine($"Элемент массива под индексом {i} = {mass[i]}");
- }
- Console.WriteLine($"Их сумма = {sumResult}");
- break;
- case 3:
- int isNull = 0;
- Console.Write("Введите размер массива = ");
- mass = new int[Convert.ToInt32(Console.ReadLine())];
- for (int i = 0; i < mass.Length; i++)//Вводим элементы
- {
- Console.Write($"Введите элемент массива под индексом {i} = ");
- mass[i] = Convert.ToInt32(Console.ReadLine());
- }
- foreach(int m in mass)
- {
- if(m == 0)
- {
- isNull++;
- }
- if(isNull == 1)
- {
- sumResult += m;
- }
- }
- Console.WriteLine($"Сумма: {sumResult}");
- break;
- case 4:
- Console.Write("Введите A = ");
- int A = Convert.ToInt32(Console.ReadLine());
- mass = new int[20];
- for(int i = 0; i < mass.Length; i++)
- {
- mass[i] = random.Next(0, 100);
- if (A < mass[i])
- {
- Console.WriteLine($"Элемент массива с индексом {i} = {mass[i]} больше чем A");
- }
- }
- break;
- case 5:
- Console.Write("Введите размер массива = ");
- mass = new int[Convert.ToInt32(Console.ReadLine())];
- int[] newMass = new int[mass.Length];
- for (int i = 0; i < mass.Length; i++)//Вводим элементы рандома
- {
- mass[i] = random.Next(0, 100);
- }
- for (int i = 0; i < mass.Length; i++)
- {
- if(i == mass.Length - 1)
- newMass[i] = (mass[i] + mass[i - 1]) / 2;
- else if (i==0)
- newMass[i] = (mass[i] + mass[i + 1]) / 2;
- else
- {
- newMass[i] = (mass[i] + mass[i + 1] + mass[i-1]) / 2;
- }
- Console.WriteLine($"Старый массив, элемент под индексом {i} = {mass[i]}\t\t\tНовый массив, элемент под индексом {i} = {newMass[i]}");
- }
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement