Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1.  static int numberOfLoops;
  2.         static int numberOfIterations;
  3.         static int[] loops;
  4.  
  5.         static void Main()
  6.         {
  7.             Console.Write("N = ");
  8.             numberOfLoops = int.Parse(Console.ReadLine());
  9.             numberOfIterations = numberOfLoops;
  10.             loops = new int[numberOfLoops];
  11.             NestedLoops(0);
  12.  
  13.         }
  14.  
  15.         static void NestedLoops(int currentLoop)
  16.         {
  17.             if (currentLoop == numberOfLoops)
  18.             {
  19.                 PrintLoops();
  20.                 return;
  21.             }
  22.             for(int counter = 1; counter <= numberOfIterations; counter++)
  23.             {
  24.                 loops[currentLoop] = counter;
  25.                 NestedLoops(currentLoop + 1);
  26.             }
  27.         }
  28.         static void PrintLoops()
  29.         {
  30.             for(int i = 0; i < numberOfLoops; i++)
  31.             {
  32.                 Console.Write("{0} ",loops[i]);
  33.  
  34.             }
  35.             Console.WriteLine();
  36.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement