using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DraftForLab2 { class Program { static void DoBlock_1() { Console.WriteLine("Введіть значення n: "); int n = int.Parse(Console.ReadLine()); int sum = 0; for (int i = 1; i <= n; i++) { Console.WriteLine("Введіть число: "); int number = int.Parse(Console.ReadLine()); if (i % 2 == 0) { sum += number; } } Console.WriteLine($"Сума — {sum}."); } static void DoBlock_2() { int sum = 0; int count = 0; while (true) { Console.WriteLine("Введіть число: "); int number = int.Parse(Console.ReadLine()); if (number == 0) { break; } count++; if (count % 3 == 0) { sum -= number; } else { sum += number; } } Console.WriteLine($"S = {sum}."); } static void DoBlock_3() { Console.WriteLine("Введіть значення x: "); double x = double.Parse(Console.ReadLine()); double numerator = 1.0; double denominator = 1.0; int poweroftwo = 2; for (int i = 1; i <= 6; i++) { numerator = x-(poweroftwo-1); denominator= x-poweroftwo; poweroftwo *= 2; } double p = numerator/denominator; Console.WriteLine(p); } static void Main(string[] args) { int choice; do { Console.WriteLine("Для виконання блоку 1 (варіант ...) введіть 1"); Console.WriteLine("Для виконання блоку 2 (варіант ...) введіть 2"); Console.WriteLine("Для виконання блоку 3 (варіант ...) введіть 3"); Console.WriteLine("Для виходу з програми введіть 0"); choice = int.Parse(Console.ReadLine()); switch (choice) { case 1: Console.WriteLine("Виконую блок 1"); DoBlock_1(); break; case 2: Console.WriteLine("Виконую блок 2"); DoBlock_2(); break; case 3: Console.WriteLine("Виконую блок 3"); DoBlock_3(); break; case 0: Console.WriteLine("Зараз завершимо, тільки натисніть будь ласка ще раз Enter"); Console.ReadLine(); break; default: Console.WriteLine("Команда ``{0}'' не розпізнана. Зробіть, будь ласка, вибір із 1, 2, 3, 0.", choice); break; } } while (choice != 0); } } }