SHARE
TWEET

Arrays.20.Variations

Teodor92 Jan 21st, 2013 193 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. class Variations
  4. {
  5.     static void VariationsGen(int[] array, int index, int N)
  6.     {
  7.         if (array.Length == index)
  8.         {
  9.             PrintVar(array);
  10.         }
  11.         else
  12.         {
  13.             for (int i = 1; i < N + 1; i++)
  14.             {
  15.                 array[index] = i;
  16.                 VariationsGen(array, index + 1, N);
  17.             }
  18.         }
  19.     }
  20.     static void PrintVar(int[] array)
  21.     {
  22.         for (int i = 0; i < array.Length; i++)
  23.         {
  24.             Console.Write("{0} ", array[i]);
  25.         }
  26.         Console.WriteLine();
  27.     }
  28.     static void Main()
  29.     {
  30.         int N = 5;
  31.         int K = 2;
  32.         int[] vars = new int[K];
  33.         VariationsGen(vars, 0, N);
  34.     }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top