Professional Documents
Culture Documents
h>
void combinationUtil(int arr[], int data[], int start, int end,
int index, int r);
// The main function that prints all combinations of size r
// in arr[] of size n. This function mainly uses combinationUtil()
void printCombination(int arr[], int n, int r)
{
// A temporary array to store all combination one by one
int data[r];
10. }
11.
12. // The main function that prints all combinations of size r
13. // in arr[] of size n. This function mainly uses combinationUtil()
14. void printCombination(int arr[], int n, int r)
15. {
16.
17.
int data[r];
18.
19.
20.
21.
22.
23.
24. }
25.
26. /* arr[]
27.
28.
29.
index
30.
31.
*/
32. void combinationUtil(int arr[], int n, int r, int index, int data[],
int i)
33. {
34.
35.
if (index == r)
36.
37.
38.
printf("%d ",data[j]);
39.
printf("\n");
40.
return;
41.
42.
43.
44.
if (i >= n)
45.
return;
46.
47.
48.
data[index] = arr[i];
49.
50.
51.
// Remove duplicates
52.
53.
i++;
54.
55.
56.
57.
58. }
59.
60. // Driver program to test above functions
61. int main()
62. {
63.
64.
int r = 3;
65.
int n = sizeof(arr)/sizeof(arr[0]);
66.
printCombination(arr, n, r);
67.
return 0;
68. }