- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int r[4];
- srand(time(NULL));
- re:
- for(int i=0;i<4;i++)
- {
- r[i]=rand()%10;
- for(int j=0;j<i;j++)
- {
- if(r[j]==r[i])
- {
- i--;
- break;
- }
- }
- }
- cout<<"4個介於1-9之間的不重複隨機亂數:";
- for(int i=0;i<4;i++)
- cout<<r[i]<<" ";
- cout<<endl;
- system("pause");
- goto re;
- system("pause");
- return 0;
- }
複製代碼 |