返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int r[4];
  7.     srand(time(NULL));
  8.     cout<<"4個介於0~9的不重複隨機亂數為:";
  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[i]==r[j])
  15.                {
  16.                              i--;
  17.                              break;
  18.                }   
  19.        }
  20.     }
  21.     for(int i=0;i<4;i++)
  22.         cout<<r[i]<<" ";
  23.     cout<<endl;     
  24.     system("pause");
  25.     return 0;
  26. }
複製代碼

TOP

返回列表