Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void printSubsequences(int arr[], int n, int index, int subsequence[], int length) {
- if (index == n) {
- // print the subsequence
- for (int i = 0; i < length; i++) {
- printf("%d ", subsequence[i]);
- }
- printf("\n");
- return;
- }
- // include the current element in the subsequence
- subsequence[length] = arr[index];
- printSubsequences(arr, n, index + 1, subsequence, length + 1);
- // exclude the current element from the subsequence
- printSubsequences(arr, n, index + 1, subsequence, length);
- }
- int main() {
- int arr[] = {1, 0, 3};
- int n = sizeof(arr) / sizeof(arr[0]);
- int subsequence[n];
- printf("All subsequences of the set are:\n");
- printSubsequences(arr, n, 0, subsequence, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment