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

TOP

返回列表