well friends i have to write a program which generates all combination of 1,2,3, plz give me some hints coz i have to submit it 17th jan
Printable View
well friends i have to write a program which generates all combination of 1,2,3, plz give me some hints coz i have to submit it 17th jan
How would you methodically generate all the combinations by hand?
Plan it out on paper like laserlight suggested. When you have the correct formular, ( use a calculator if it helps ) then write some puescode.
will u plz give me some example
No, we will not do your homework for you. Give it a try and post your non-working code.
lol...Code:#include <iostream>
using namespace std;
int main()
{
cout << "123" << endl;
cout << "132" << endl;
cout << "321" << endl;
cout << "312" << endl;
cout << "213" << endl;
cout << "231" << endl;
return 0;
}
Yup, the manual way is the best way. :D :D :DQuote:
Originally Posted by Sentral
*cough* combination, not permutation *cough*
So,Code:#include <iostream>
using namespace std;
int main()
{
cout << "123" << endl;
cout << "132" << endl;
cout << "213" << endl;
cin.get();
return 0;
}
> plz give me some hints
Well do what laserlight suggested.
Like 123 is
1 + all combinations of 23
2 + all combinations of 13
3 + all combinations of 12
Rinse and repeat with some recursion - should be pretty obvious.
thanx frnd
Which would mean an answer would be more like this:Quote:
Originally Posted by laserlight
Of course I doubt he actually meant combination, as he didn't state how many items to pick, only what to pick from.Code:#include <iostream>
using namespace std;
int main()
{
cout << "" << endl;
cout << "1" << endl;
cout << "2" << endl;
cout << "3" << endl;
cout << "12" << endl;
cout << "13" << endl;
cout << "23" << endl;
cout << "123" << endl;
}