Click here to Skip to main content
15,885,878 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have 3 numbers : 1,2,3. How to write an function or use build-in functions to get the result like this:
12
21
13
31
23
31
Posted

I hope you are able to slightly modify the code of permutation algorithm provided here to get the results needed.
 
Share this answer
 
C++
#include <iostream>
using namespace std;

int main()
{
  int n[3]={1,2,3};
  for (int i=0; i<3; i++)
  {
    for (int j=1; (j+i) < 3; j++)
    {
      cout << n[i] << n[j+i] << endl;
      cout << n[j+i] << n[i] << endl;
    }
  }
}
 
Share this answer
 
v2
Comments
virusx1984 31-Jul-11 19:08pm    
It doesn't work.
Emilio Garavaglia 1-Aug-11 2:31am    
If you want to take advantage by a forum don't post generic comment like "It doesn't work".
Tell EXACTLY WHAT didn't work, what was the wrong result you get and what you wold expect.
CPallini 1-Aug-11 3:34am    
What do you mean with 'it doesn't work'? On my system (WinXP with Visual Studio 2005) it compiles and runs without any problem and the output matches the expected one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900