cplusplus.com
C++ : Forum : UNIX/Linux Programming : Generate Permutations.
 
cplusplus.com
Information
Documentation
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs


post Generate Permutations.

ashmew2 (7)
Hi , I want to Generate Permutations of 5 digit with numbers 1 to 6. How Can i go about it ? Im using G++ under Ubuntu Intrepid Ibex. Permutation is Basically Arrangement. like Using 1 , 2 and 3 , The possible permutations are :

123
132
213
231
312
321

Thanks.
Last edited on
jsmith (5804)
Google next_permutation.

ashmew2 (7)
Thanks jsmith , it looks promising!
HaHai (1)
#include <iostream>

using namespace std;

int main(){
int nb[] = {1,2,3};
for(int a=0; a<3; a++)
for(int b=0; b<3; b++)
for(int c=0; c<3; c++)
if(a!=b && a!=c && b!=c)
cout << nb[a] << nb[b] << nb[c] << endl;
return 0;

}
ashmew2 (7)
Thankyou HaHai.
Topic archived. No new replies allowed.