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