#include <iostream> using namespace std; void PrintPermutation(int n, int *A, int cur) { if(n == cur) { for(int i = 0; i < cur; i++) { printf("%d ", A[i]); } printf("\n"); } else { bool ok = false; for(int i = 0; i < n; i++) { ok = true; for(int j = 0; j < cur; j++) { if(A[j] == i) ok = false; } if(ok == true) { A[cur] = i; PrintPermutation(n, A, cur+1); } } } } int main() { int n = 5; int A[1000] = {0}; PrintPermutation(n, A, 0); system("pause"); return 0; }