Advertisement
filin

laba_2_z_1_mk1

Sep 9th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using static System.Collections.Specialized.BitVector32;
  7.  
  8. namespace Z_1
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int q = 1;
  15.             while (q == 1)
  16.             {
  17.                 Console.WriteLine("Введите начало диапазона");
  18.                 int a = int.Parse(Console.ReadLine());
  19.                 Console.WriteLine("Введите конец диапазона");
  20.                 int b = int.Parse(Console.ReadLine());
  21.                 Console.WriteLine("Выберите способ 1, 2 или 3.");
  22.                 int ch = int.Parse(Console.ReadLine());
  23.                 switch (ch)
  24.                 {
  25.                     case 1: f1(a, b); break;
  26.                     case 2: f2(a, b); break;
  27.                     case 3: f3(a, b); break;
  28.                     default: Console.WriteLine("Способ не выбран"); break;
  29.                 }
  30.                 Console.WriteLine("Если хотите продолжить введите 1");
  31.                 q = int.Parse(Console.ReadLine());
  32.             }
  33.         }
  34.         static void f1(int a, int b)
  35.         {
  36.             while (a <= b)
  37.             {
  38.                 if (a > 0)
  39.                 {
  40.                     Console.Write(a + " ");
  41.                 }
  42.                 a++;
  43.             }
  44.             Console.WriteLine("");
  45.         }
  46.         static void f2(int a, int b)
  47.         {
  48.             do
  49.             {
  50.                 if (a > 0)
  51.                 {
  52.                     Console.Write(a + " ");
  53.                 }
  54.                 a++;
  55.             }
  56.             while (a <= b);
  57.             Console.WriteLine("");
  58.         }
  59.         static void f3(int a, int b)
  60.         {
  61.             for (int i = a; i <= b; i++)
  62.             {
  63.                 {
  64.                     if (i > 0)
  65.                     {
  66.                         Console.Write(i + " ");
  67.                     }
  68.                 }
  69.             }
  70.             Console.WriteLine("");
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement