Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- int k = int.Parse(Console.ReadLine());
- int n = int.Parse(Console.ReadLine());
- int[] array = new int[k];
- GetVariations(array, 0, n); //Input given consists of: array(with defined size), starting index 0 and the max number
- }
- private static void GetVariations(int[] array, int k, int n)
- {
- if (k == array.Length) //Recursion bottom - when k reaches max the result is printed
- {
- PrintResult(array);
- }
- else
- {
- for (int i = 1; i <= n; i++)
- {
- array[k] = i;
- GetVariations(array, k + 1, n); //The recursive element increases the index k with 1 on each call
- }
- }
- }
- private static void PrintResult(int[] array)
- {
- foreach (var number in array)
- {
- Console.Write(number + " ");
- }
- Console.WriteLine();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement