- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- //產生20組數值,每組皆包含4個介於0~9之隨機亂數,每隔 0.5秒 產生一組。_sleep(N)可讓程式暫停執行N毫秒
- int t=0;
- srand(time(NULL));
- int n[4];
- for(;;){
- for(int j=1; j<=4; j++){
- n[j-1]=rand()%10;
-
- }
- t++;
- for(int k=0;k<=3;k++){
- cout<<n[k]<<" ";
- }
- if(n[0]==n[1] and n[1]==n[2] and n[2]==n[3]){
- cout<<"第"<<t<<"次"<<endl;
- goto w;
- }
- cout<<endl;
-
- }
- w:
- system("pause");
- return 0;
- }
複製代碼 |