Give a similar one here: Find 4 numbers in an integer array and they sum zero
Anonymous
Why not just find all the combinations of 4 elements in the array and print out the one whose sum is equal to the required number: void get_sum(vector&vec, int n, int indx,int sum) { static vector res; if (n == 0) { int temp = 0; for (auto &a : res)temp += a; if (temp == sum) { for (auto &a : res) cout vec = { 1, 2, 3, 4, 5, 6, 7, 8 }; get_sum(vec, 4, 0, 11); }
Check out your Company Bowl for anonymous work chats.