返回列表 發帖
本帖最後由 陳妍蓁 於 2024-8-3 16:19 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main(){
  6. srand(time(NULL));
  7.     cout<<"4個介於0~9之不重複隨機亂數:"<<endl;
  8.     int n[]={0,0,0,0};
  9.     for(int i=1;i<=20;i++){

  10.         for(int j=0;j<=3;j++){
  11.         n[j]=rand()%10;

  12.         if(n[0]==n[1] || n[0]==n[2] || n[0]==n[3] || n[1]==n[2] || n[1]==n[3] || n[2]==n[3])
  13.         {
  14.             j--;
  15.             break;
  16.         }
  17.         cout<<n[j];

  18.      }
  19.      cout<<endl;
  20.      _sleep(500);

  21.     }
  22.     system("pause");
  23.     return 0;


  24. }
複製代碼

TOP

返回列表