fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. int number = 0 ;
  9. int temp1 = 0 ;
  10. int temp2 = 0 ;
  11. int temp3 = 1 ;
  12. int x = 0 ;
  13. int y = 1 ;
  14. int z = 0 ;
  15. int a[x]; // 待使用者輸入數字後再決定長度
  16. int b[z];
  17.  
  18. printf("Please enter a number: ");
  19. cin >> number ; // 讀入數字
  20.  
  21. temp1 = number ;
  22. while ( x < temp1) {
  23. a[x]= y ;
  24. x++;
  25. y++;
  26. // 開始產生陣列, 長度為使用者輸入之數字
  27. // 例如: 輸入5則 a[0] = 1, a[1]=2, ..., a[4]=5;
  28. }
  29.  
  30. while( temp1 > 0 ) {
  31. temp3 = temp3 *temp1 ;
  32. temp1 = temp1 -1 ; //求出幾種排列 例: 輸入5則有5*4*3*2*1種排列.
  33. }
  34.  
  35. temp2 = temp3/number; // 每個數字開頭有幾個 例: 輸入5則每個數字開頭有24種排列, 總共120種排列
  36. printf("%d", temp2);
  37.  
  38.  
  39. }
Success #stdin #stdout 0s 3472KB
stdin
5
stdout
Please enter a number: 24