Code:-
#include<iostream>
#include<vector>
using namespace std;
void recursion(int sum,int i,vector<int> v,int size)
{
vector<int> v1=v;
int size1=size;
if(sum==0)
{
for(int k=0;k<size;k++)
cout<<v[k]<<" ";
cout<<endl;
}
else
{
for(int j=i+1;j<10;j++)
{
size=size1+1;
v1=v;
v1.insert(v1.end(),j);
recursion(sum-j,j,v1,size);
}
}
}
int main()
{
int sum=10;
int size=0;
vector<int> v;
recursion(10,0,v,size);
system("pause");
}
output:-1 2 3 4
1 2 7
1 3 6
1 4 5
1 9
2 3 5
2 8
3 7
4 6
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.