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

TOP

返回列表