Advertisement
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 Z_1
- {
- class Program
- {
- enum Methods
- {
- While = 1,
- DoWhile = 2,
- For = 3
- }
- static void Main(string[] args)
- {
- Console.Title = "laba2_1";
- Console.WriteLine("Программа выводит только положительные целые числа из диапазона от А до В (A<=В);");
- string q;
- do
- {
- Int64 leftBorder, rightBorder;
- do
- {
- Console.Write("Введите начало диапазона: ");
- leftBorder = (Int64)Math.Ceiling(EnterDouble());
- Console.Write("Введите конец диапазона: ");
- rightBorder = (Int64)Math.Floor(EnterDouble());
- if (leftBorder < rightBorder)
- {
- Console.WriteLine("Выберите способ: \n1)While \n2)DoWhile \n3)For");
- Console.Write("Введите номер способа: ");
- Methods number = (Methods)EnterInt();
- switch (number)
- {
- case Methods.While:
- {
- While(leftBorder, rightBorder);
- }
- break;
- case Methods.DoWhile:
- {
- DoWhile(leftBorder, rightBorder);
- }
- break;
- case Methods.For:
- {
- For(leftBorder, rightBorder);
- }
- break;
- default:
- {
- Console.WriteLine("Способ не выбран");
- }
- break;
- }
- }
- else
- {
- Console.WriteLine("Недопустимое значение: a>b. Введите a и b заново");
- }
- CheckRange(rightBorder);
- } while (leftBorder > rightBorder);
- Console.WriteLine("Если хотите продолжить введите 1");
- q = Console.ReadLine();
- }
- while (q.Equals("1"));
- }
- static void While(Int64 a, Int64 b)
- {
- while (a <= b)
- {
- if (a > 0)
- {
- Console.Write("{0} ", a);
- }
- a++;
- }
- Console.WriteLine();
- }
- static void DoWhile(Int64 a, Int64 b)
- {
- do
- {
- if (a > 0)
- {
- Console.Write("{0} ", a);
- }
- a++;
- }
- while (a <= b);
- Console.WriteLine();
- }
- static void For(Int64 a, Int64 b)
- {
- for (Int64 i = a; i <= b; i++)
- {
- {
- if (i > 0)
- {
- Console.Write("{0} ", i);
- }
- }
- }
- Console.WriteLine();
- }
- static double EnterDouble()
- {
- double value;
- bool result = false;
- result = double.TryParse(Console.ReadLine(), out value);
- if (result == false)
- {
- do
- {
- Console.Write("Некорректные данные. Введите заново: ");
- result = double.TryParse(Console.ReadLine(), out value);
- }
- while (!result);
- }
- return value;
- }
- static int EnterInt()
- {
- int value;
- bool result = false;
- result = int.TryParse(Console.ReadLine(), out value);
- if (result == false)
- {
- do
- {
- Console.Write("Некорректные данные. Введите заново: ");
- result = int.TryParse(Console.ReadLine(), out value);
- }
- while (!result);
- }
- return value;
- }
- static void CheckRange(Int64 rightBorder)
- {
- if (rightBorder < 0)
- {
- Console.WriteLine("В этом диапазоне нет положительных чисел");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement