新聞中心

        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隨機選號

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 庆云县| 渝中区| 大邑县| 青浦区| 平原县| 遂川县| 永仁县| 自治县| 淮安市| 宁远县| 临沧市| 丘北县| 澄迈县| 乌兰县| 巴青县| 弥勒县| 西平县| 海安县| 涞水县| 嵩明县| 长丰县| 定襄县| 开远市| 邹平县| 桓仁| 建始县| 松原市| 罗甸县| 漠河县| 会东县| 石家庄市| 平南县| 镇宁| 海城市| 灵武市| 石城县| 红原县| 华坪县| 嵩明县| 柳州市| 蓝田县|