Advertisement
stanevplamen

02.Rec.VariationsN

May 29th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2.  
  3. class VariationsN
  4. {
  5.     static int number;
  6.     static int numberOfLoops;
  7.     static int[] vector;
  8.  
  9.     static void Main()
  10.     {
  11.         Console.Write("n = ");
  12.         number = int.Parse(Console.ReadLine());
  13.         numberOfLoops = number;
  14.         vector = new int[numberOfLoops];
  15.         Generic(0);
  16.     }
  17.  
  18.     static void Generic(int currentLoop)
  19.     {
  20.         if (currentLoop == numberOfLoops)
  21.         {
  22.             Print();
  23.             return;
  24.         }
  25.         else
  26.         {
  27.             for (int i = 1; i <= numberOfLoops; i++)
  28.             {
  29.                 vector[currentLoop] = i;
  30.                 Generic(currentLoop + 1);
  31.             }
  32.         }
  33.     }
  34.  
  35.     static void Print()
  36.     {
  37.         foreach (int c in vector)
  38.         {
  39.             Console.Write("{0} ", c);
  40.         }
  41.         Console.WriteLine();
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement