1 include<iostream> 2 3 using namespace std; 4 5 int num[5]={1,2,3,4,5}; 6 int sum; 7 8 void swap(int *p,int *q) 9 { 10 int m = *p; 11 *p=*q; 12 *q=m; 13 } 14 void pai(int x,int y) 15 { 16 if(x>y) 17 { 18 for(int i = 0; i <= y; i++) 19 cout<<num[i]<<' '; 20 cout<<endl; 21 sum++; 22 } 23 else 24 { 25 for(int i = x; i <= y; i++) 26 { 27 swap(&num[x],&num[i]); 28 pai(x+1,y); 29 swap(&num[x],&num[i]); 30 } 31 } 32 } 33 int main() 34 { 35 pai(0,4); 36 cout<<sum<<endl; 37 }