Functions and Recursions – Strings – Problem #9
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
Suppose you are given an integer array a[]. The array may contain repeated numbers. You are also given an integer 'l'. Your task is to find all possible combinations of numbers in a[] that have length 'l' (repetition is allowed). For example, consider a[] = {5, 7, 12} and l = 2. Then the possible combinations are: (5, 5), (5, 7), (5, 12), (7,7), (7, 12), (12, 12). If a[] = {5, 7, 12, 3} and l = 3, then there can be following combinations: 5 5 5 5 5 7 5 5 12 5 5 3 5 7 7 5 7 12 5 7 3 5 12 12 5 12 3 5 3 3 7 7 7 7 7 12 7 7 3 7 12 12 7 12 3 7 3 3 12 12 12 12 12 3 12 3 3 3 3 3 Your task is to write a recursive function to solve the problem. The user should supply the array a[] and an integer l as input, and the program should list all possible such combinations (order of numbers does not matter). Comment and indent your code properly.