當前位置:編程學習大全網 - 編程軟體 - C語言編程: 輸出1,2,3,4這4個數字的所有可能的排列

C語言編程: 輸出1,2,3,4這4個數字的所有可能的排列

// 作者:小斌

#include <iostream>

using namespace std;

void perm(char *s, int k, int n)

{

if(k==n)

{

for(int i=0; i<=n; i++)

cout<<s[i];

cout<<'\n';

}

else

{

char temp;

for(int i=k; i<=n; i++)

{

temp=s[i];

s[i]=s[k];

s[k]=temp;

perm(s, k+1, n);

temp=s[i];

s[i]=s[k];

s[k]=temp;

}

}

}

int main()

{

char s[4]={'1', '2', '3', '4'};

//char *s="1234 ";

perm(s, 0, 3);

return 0;

}

  • 上一篇:.數據庫設計分為幾個階段,各階段的任務是什麽?
  • 下一篇:CAXA線切割xp是什麽
  • copyright 2024編程學習大全網