suppose you have a number 1234 how to code solution in c so as to find all the possible combnations of this number. eg : 1423, 1324,3214 etc....
TIA
~codomaniac
suppose you have a number 1234 how to code solution in c so as to find all the possible combnations of this number. eg : 1423, 1324,3214 etc....
TIA
~codomaniac
Here's how to do it using STL containers/algorithms:
Code:#include <algorithm> #include <iostream> #include <set> int main() { int Numbers[] = {1, 2, 3, 4}; std::set<int> S(Numbers, Numbers + (sizeof(Numbers) / sizeof(int))); do { std::copy(S.begin(), S.end(), std::ostream_iterator<int>(std::cout, " ")); std::cout << std::endl; } while(std::next_permutation(S.begin(), S.end())); return 0; }
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Permute 1
Dead easy
Permute 12
Pretty easy, 12 or 21
Permute 123
That's just
1 with permutations of 23
2 with permutations of 13
3 with permutations of 12
Since you already know how to permute a pair of digits, it shouldn't be hard
Permute 1234
1 with permutations of 234
....
Get the picture?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
no sirs ! I am bit confused as to how get permutations ! . How to program it in C. It would be nice if you tell me the logic involved in simple steps.
TIA
~codomaniac
I thought that was pretty simple
The only way it's going to get simpler is by handing over the source code for your homework
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.