- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- re:
- system("cls");
- int r[6];
- string name[]={"周雍程","張峻瑋","林宇翔","李允軒","張郁庭","張彥承"};
- for(int i=0; i<3; i++)
- {
- r[i]=rand()%6;
- for(int j=0; j<i; j++)
- {
- if(r[i]==r[j])
- {
- i--;
- break;
- }
- }
- }
- cout<<"隨機抽出的三位同學為: ";
- for(int i=0; i<3; i++)
- cout<<name[r[i]]<<" ";
- cout<<endl;
- system("pause");
- system("cls");
- goto re;
- return 0;
- }
複製代碼 |