返回列表 發帖
本帖最後由 高昀昊 於 2022-4-16 14:36 編輯
  1. #include<cstdlib>
  2. #include<iostream>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     cout<<"4個介於0~9的不隨機亂數:"<<endl;   
  8.     int n[4];
  9.     srand(time(NULL));
  10.     for(int i=0; i<20; i++)
  11.     {
  12.         for(int j=0; j<4; j++)
  13.         {
  14.             n[j]=rand()%10;
  15.             for(int k=0; k<j; k++)      
  16.             {
  17.                 if(n[k]==n[j])
  18.                 {
  19.                     j--;
  20.                     break;              
  21.                 }
  22.             }
  23.         }  
  24.         for(int j=0; j<4; j++)
  25.         {
  26.             cout<<n[j]<<" ";
  27.         }
  28.         cout<<endl;
  29.         _sleep(500);
  30.     }
  31.     system("pause");
  32.     return 0;   
  33. }
複製代碼

TOP

返回列表