专注电子技术学习与研究
当前位置:单片机教程网 >> MCU设计实例 >> 浏览文章

C++30选7随机选号器程序

作者:黄波海   来源:本站原创   点击数:  更新时间:2014年03月06日   【字体:

 

// a1.cpp : 定义控制台应用程序的入口点。

//
 
#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控制了函数的通断
{
arr[k]=tem;
break;
}
}
}
 
for(int l=0;l<7;l++)
{
printf("%d\t",arr[l]);
}
return 0;
}
关闭窗口

相关文章