新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > C++30選7隨機選號器程序

C++30選7隨機選號器程序

作者: 時間:2016-12-01 來源:網(wǎng)絡(luò) 收藏
// a1.cpp : 定義控制臺應(yīng)用程序的入口點。
//
#include "stdafx.h"
#include "time.h"
#include "stdlib.h"
int _tmain(int argc, _TCHAR* argv[])
{
int arr[]={0,0,0,0,0,0,0};
int tm=time(NULL);
srand(tm);
for(int k=0;k<7;k++)
{
while(1)
{
bool ist=false;
int tem=rand()%31;
for(int i=0;i<7;i++)
{
if(arr[i]==tem)//截斷語句
{
ist=true;
}
}
if(ist==false)//通過ist控制了函數(shù)的通斷
{
arr[k]=tem;
break;
}
}
}
for(int l=0;l<7;l++)
{
printf("%d ",arr[l]);
}
return 0;
}


關(guān)鍵詞: C++30選7隨機選號

評論


技術(shù)專區(qū)

關(guān)閉