Hi Sharad,

I suppose this is what you are looking for. Assume non-negative integers.
Otherwise, there are infinite possibilities.

#include<iostream>
#include<set>
#include<vector>
using namespace std;

vector< vector<int> > allCombinations;

void findAllCombinations(vector<int> elements, int left)
{
  if(left < 0) return;
  else if(left == 0) allCombinations.push_back(elements);
  else{
    int temp = elements[elements.size()-1];
    for(int i=temp+1;i<=left;i++)
    {
      elements.push_back(i);
      findAllCombinations(elements,left-i);
      elements.pop_back();
    }
  }
}

void displayAllCombinations()
{
  for(int i=0;i<allCombinations.size();i++)
  {
    for(int j=0;j<allCombinations[i].size();j++)
      cout << allCombinations[i][j] << " ";
    cout <<endl;
  }
}

int main()
{
  vector<int> temp;
  temp.push_back(0);
  int n = 10;
  findAllCombinations(temp,n);
  displayAllCombinations();
}

Raajay

On Tue, Jun 22, 2010 at 13:43, sharad kumar <[email protected]>wrote:

> i knoe c++ well so i can understand java code bt
> i m not able to understand this code so plzzzz explain it or give algo
> thnx in advance
>
> --
> 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]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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.

Reply via email to