專(zhuān)注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

C++30選7隨機(jī)選號(hào)器程序

作者:黃波海   來(lái)源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2014年03月06日   【字體:

 

// a1.cpp : 定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。

//
 
#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)//截?cái)嗾Z(yǔ)句
{
ist=true;
}
}
if(ist==false)//通過(guò)ist控制了函數(shù)的通斷
{
arr[k]=tem;
break;
}
}
}
 
for(int l=0;l<7;l++)
{
printf("%d\t",arr[l]);
}
return 0;
}
關(guān)閉窗口

相關(guān)文章