What will be the output for the following code?
#include<stdio.h>
void combination(int arr[],int n,int r,int index,int aux[],int i);
void print(int arr[], int n, int r)
{
int aux[r];
combination(arr, n, r, 0, aux, 0);
}
void combination(int arr[], int n, int r, int index, int aux[], int i)
{
if (index == r)
{
for (int j=0; j<r; j++)
printf("%d ",aux[j]);
printf(", ");
return;
}
if (i >= n)
return;
aux[index] = arr[i];
combination(arr, n, r, index+1, aux, i+1);
combination(arr, n, r, index, aux, i+1);
}
int main()
{
int arr[] = {1, 2,2};
int r = 2;
int n = sizeof(arr)/sizeof(arr[0]);
print(arr, n, r);
return 0;
}
#include<stdio.h>
void combination(int arr[],int n,int r,int index,int aux[],int i);
void print(int arr[], int n, int r)
{
int aux[r];
combination(arr, n, r, 0, aux, 0);
}
void combination(int arr[], int n, int r, int index, int aux[], int i)
{
if (index == r)
{
for (int j=0; j<r; j++)
printf("%d ",aux[j]);
printf(", ");
return;
}
if (i >= n)
return;
aux[index] = arr[i];
combination(arr, n, r, index+1, aux, i+1);
combination(arr, n, r, index, aux, i+1);
}
int main()
{
int arr[] = {1, 2,2};
int r = 2;
int n = sizeof(arr)/sizeof(arr[0]);
print(arr, n, r);
return 0;
}A. 1 2, 1 2, 2 2
B. 1 2, 1 2, 2 2 ,
C. 1 2, 2 1, 2 2 ,
D. 1 2, 2 1, 2 2
Answer: Option B
Related Questions on Miscellaneous on Data Structures
Which data structure is used to implement a binary heap efficiently?
A. Array
B. Linked List
C. Stack
D. Queue
In which scenario would you use a Bloom Filter?
A. For implementing a stack-based algorithm
B. To maintain a balanced binary tree
C. For efficient sorting of elements
D. To test membership in a large dataset
A. Queue
B. Stack
C. Heap
D. Array

Join The Discussion