Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class NumberCombinations
- {
- static void Combinations(int index, int[] vector, int numbersLength, int start)
- {
- if (index == -1)
- {
- Print(vector);
- }
- else
- {
- for (int i = start; i <= numbersLength; i++)
- {
- vector[index] = i;
- Combinations(index - 1, vector, (numbersLength), (i + 1));
- }
- }
- }
- static void Print(int[] vector)
- {
- foreach (int i in vector)
- {
- Console.Write("{0} ", i);
- }
- Console.WriteLine();
- }
- static void Main()
- {
- Console.Write("Please enter the amount of the numbers 1...N, N = ");
- int numbersAmount = int.Parse(Console.ReadLine());
- Console.Write("Please enter the amount of the combinations K = ");
- int combinationsAmount = int.Parse(Console.ReadLine());
- int[] vector = new int[combinationsAmount];
- Combinations(combinationsAmount - 1, vector, numbersAmount, 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement