Functions and Recursions – Strings – Problem #9

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: hard

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.

Back to Lab Problems
Functions and Recursions/Strings/Problem #9

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #9

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.