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

TOP

返回列表