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