online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> #include <vector> using namespace std; void get_target_sum(std::vector<std::vector<int>>& total_ans, std::vector<int>& curr_ans, int num_remaining, int targetnum){ // total_ans denotes all the tuples, curr_ans denotes the current // computation, num_remaining denotes the numbers remaining which // should sum up to targetnum. // each time we find a valid number which can be a part of our answer, we // add it to curr_ans, decrement num_remaining since the numbers remaining // has decreased by 1, and decrease the target number to be found by the // value of the number if(num_remaining<1){return;} if(num_remaining==1){ curr_ans.push_back(targetnum); total_ans.push_back(curr_ans); curr_ans.pop_back(); } for(int curr_num=0;curr_num<targetnum;curr_num++){ curr_ans.push_back(curr_num); get_target_sum(total_ans,curr_ans,num_remaining-1,targetnum-curr_num); curr_ans.pop_back(); } } int main() { std::vector<std::vector<int>>final_ans; std::vector<int> curr_ans; get_target_sum(final_ans,curr_ans,3,4); for(int i=0;i<final_ans.size();i++){ std::cout<<1<<" "; // The first variable for(auto num:final_ans[i]){ std::cout<<num+2<<" "; // the other 3 variables, incremented by 2. } std::cout<<"\n"; } return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue