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