filin

laba_5_z_4_new

Oct 20th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 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.  
  7. namespace Z_4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Title = "Laba5_4";
  14.             Console.WriteLine("рекурсивный метод для вывода на экран");
  15.             Console.Write("Введите натуральное число, n=");
  16.             int n = EnterInt();
  17.             for (int i = 1; i <= n; i++)
  18.             {
  19.                 recursion(i);
  20.                 Console.WriteLine("\n");
  21.             }
  22.             Console.ReadKey();
  23.         }
  24.         static void recursion(int n)
  25.         {
  26.             {
  27.                 if (n > 0)
  28.                 {
  29.                     Console.Write("{0} ", n);
  30.                     recursion(n - 1);
  31.                 }
  32.             }
  33.         }
  34.         static int EnterInt()
  35.         {
  36.             int value;
  37.             bool result = false;
  38.             result = int.TryParse(Console.ReadLine(), out value);
  39.             if (result == false)
  40.             {
  41.                 do
  42.                 {
  43.                     Console.Write("Некорректные данные. Введите заново: ");
  44.                     result = int.TryParse(Console.ReadLine(), out value);
  45.                 }
  46.                 while (!result);
  47.             }
  48.             return value;
  49.         }
  50.  
  51.     }
  52. }
Add Comment
Please, Sign In to add comment