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