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_4
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Title = "Laba5_4";
- Console.WriteLine("рекурсивный метод для вывода на экран");
- Console.Write("Введите натуральное число, n=");
- int n = EnterInt();
- for (int i = 1; i <= n; i++)
- {
- recursion(i);
- Console.WriteLine("\n");
- }
- Console.ReadKey();
- }
- static void recursion(int n)
- {
- {
- if (n > 0)
- {
- Console.Write("{0} ", n);
- recursion(n - 1);
- }
- }
- }
- 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;
- }
- }
- }
Add Comment
Please, Sign In to add comment