Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define SIZE 4
- void printCombinationsWithRepetitions(int * arr, int * combs, int index,
- int sizeOfComb, int beg, int end)
- {
- if (index == sizeOfComb)
- {
- for (int i = 0; i < index; ++i)
- std::cout << arr[combs[i]];
- std::cout << '\n';
- return;
- }
- for (int j = beg; j <= end; ++j)
- {
- combs[index] = j;
- printCombinationsWithRepetitions(arr, combs, index + 1, sizeOfComb, j, end);
- }
- }
- void combinationsWithRepetitions(int * arr, int size, int sizeOfComb)
- {
- int * temp = new int[sizeOfComb + 1];
- printCombinationsWithRepetitions(arr, temp, 0, sizeOfComb, 0, size - 1);
- delete[] temp;
- }
- int main()
- {
- int * arrayOfNumbers = new int[SIZE];
- for (int i = 0; i < SIZE; ++i)
- arrayOfNumbers[i] = i + 1;
- int sizeOfComb = 2;
- combinationsWithRepetitions(arrayOfNumbers, SIZE, sizeOfComb);
- delete[] arrayOfNumbers;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement