本帖最後由 高昀昊 於 2022-4-16 14:36 編輯
- #include<cstdlib>
- #include<iostream>
- #include<ctime>
- using namespace std;
- int main()
- {
- cout<<"4個介於0~9的不隨機亂數:"<<endl;
- int n[4];
- srand(time(NULL));
- for(int i=0; i<20; i++)
- {
- for(int j=0; j<4; j++)
- {
- n[j]=rand()%10;
- for(int k=0; k<j; k++)
- {
- if(n[k]==n[j])
- {
- j--;
- break;
- }
- }
- }
- for(int j=0; j<4; j++)
- {
- cout<<n[j]<<" ";
- }
- cout<<endl;
- _sleep(500);
- }
- system("pause");
- return 0;
- }
複製代碼 |