新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > C++30选7随机选号器程序

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

作者:时间:2016-12-01来源:网络收藏
// 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 ",arr[l]);
}
return 0;
}


关键词: C++30选7随机选号

评论


相关推荐

技术专区

关闭