I am beginner in C++ and have been trying to get an output of all the sums from 4 different lists of numbers. I want to know all the possible sums using up to 1 from each list. Repeats can be omitted.
For example with an input of [1, 2], [1, 3], [2, 3], [2, -1]
should output [-1, 0, 1, 2, 3, ... 10]
.
My lists are 4, 6, 6, and 9 digits long, should that make a difference?
I have tried
#include<bits/stdc++.h>
using namespace std;
void subsetSums(int arr[], int l, int r,
int sum=0)
{
// Print current subset
if (l > r)
{
cout << sum << " ";
return;
}
subsetSums(arr, l+1, r, sum+arr[l]);
subsetSums(arr, l+1, r, sum);
}
int main()
{
int arr[] = {7, 14, 21, 28}, {-10, -20, -30, -40, -50, -60};
int n = sizeof(arr)/sizeof(arr[0]);
subsetSums(arr, 0, n-1);
return 0;
}
But it only produces an error:
expected unqualified-id before ‘{’ token
int arr[] = {5, 4, 3}, {4, -1, 5};