simonradev

Нищо Не Разбирам

Nov 25th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System.Linq;
  2. using System.Collections.Generic;
  3. using System;
  4.  
  5. namespace NestedLoops
  6. {
  7.     class Program
  8.     {
  9.         static int[] row;
  10.         static int cols;
  11.        
  12.         public static void Main(string[] args)
  13.         {
  14.             //въведи число по-малко от 5 ако не искаш да умреш :Д
  15.             int number = int.Parse(Console.ReadLine());
  16.            
  17.             cols = number;
  18.            
  19.             row = new int[cols];
  20.            
  21.             NestedLoops(0);
  22.            
  23.             Console.Write("Press any key to continue . . . ");
  24.             Console.ReadKey(true);
  25.         }
  26.        
  27.         static void NestedLoops(int currentLoop)
  28.         {
  29.             if (currentLoop == cols)
  30.             {
  31.                 PrintLoops();
  32.                 return;
  33.             }
  34.            
  35.             for (int counter = 1; counter <= cols; counter++)
  36.             {
  37.                 row[currentLoop] = counter;
  38.                 NestedLoops(currentLoop + 1);
  39.             }
  40.         }
  41.        
  42.         static void PrintLoops()
  43.         {
  44.             for (int i = 0; i < cols; i++)
  45.             {
  46.                 Console.Write("{0} ", row[i]);
  47.             }
  48.             Console.WriteLine();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment