// C# program to print all // combination of size r // in an array of size n using System; public class Lab4_1Nisan2021 { // Driver Code static public void Main() { string[] choices = {"boncuk1", "boncuk2", "boncuk3", "boncuk4", "boncuk5", "boncuk6", "boncuk7"}; int r = 2; int n = choices.Length; Console.WriteLine("You can make {0} different combinations and they're as follows: ",(n*(n-1))/r); printCombination(choices, n, r); } static void combinationUtil(string[] choices, string[] data, int start, int end, int index, int r) { // Current combination is // ready to be printed, // print it if (index == r) { for (int j = 0; j < r; j++) Console.Write(data[j] + " "); Console.WriteLine(""); return; } // replace index with all // possible elements. The // condition "end-i+1 >= // r-index" makes sure that // including one element // at index will make a // combination with remaining // elements at remaining positions for (int i = start; i <= end && end - i + 1 >= r - index; i++) { data[index] = choices[i]; combinationUtil(choices, data, i + 1, end, index + 1, r); } } // The main function that prints // all combinations of size r // in arr[] of size n. This // function mainly uses combinationUtil() static void printCombination(string[] choices, int n, int r) { // A temporary array to store // all combination one by one string[] data = new string[r]; // Print all combination // using temprary array 'data[]' combinationUtil(choices, data, 0, n - 1, 0, r); } }