從1-49選6個不同的數,輸出5組(一)

#include<iostream>
#include<ctime>
#include<stdlib.h>
using namespace std;
int main()
{

int seed[6]={0};

     int n=5;
srand( (unsigned)time( NULL ));//產生種子,不要放在循環語句裏!
loop1:
while(n)
{

for(int i=0;i<6;i++) //產生seed數組隨機數

 
seed[i]=rand()%49+1;


}
for(int k=0;k<5;k++)     //判斷seed數組裏是否有重複的數
{
for(int j=k+1;j<6;j++)
if(seed[k]==seed[j])
goto loop1;
}
for( int j=0;j<6;j++)  //輸出數組
{
cout<<seed[j]<<" ";
}
cout<<endl;
n--;
 


}
return 0;

}
發佈了17 篇原創文章 · 獲贊 1 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章