分享

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

 共同成长888 2015-07-19

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

 

// 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;
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多