標(biāo)題:
C++語(yǔ)言 福利彩票的中獎(jiǎng)號(hào)碼
[打印本頁(yè)]
作者:
51hei社區(qū)
時(shí)間:
2016-1-10 23:27
標(biāo)題:
C++語(yǔ)言 福利彩票的中獎(jiǎng)號(hào)碼
本帖最后由 51hei社區(qū) 于 2016-1-10 23:29 編輯
由于格式的問(wèn)題本程序需要手動(dòng)去掉每行尾部的-
#include<iostream>-
#include<iomanip>-
#include<time.h>-
using namespace std;-
int fun(int h,int a[],int i);-
void main()-
{int i=1,h,a[6],k=0;-
srand(time(0));-
a[0]=rand()%33;-
while(a[0]==0) //除去a[0]中的0-
{ -
a[0]=rand()%33;-
}-
-
cout<<"今晚的福利彩票的中獎(jiǎng)號(hào)碼是:"<<endl;-
-
while(i<6)-
{ h=rand()%33;-
a[i]=h;-
if(fun(h,a,i)) i++; //除去隨機(jī)數(shù)中的相同數(shù)-
}-
cout<<setfill(' ')<<setw(2)<<' '<<setfill('*')-
<<setw(22)<<'*'<<endl; //美化 -
cout<<setfill(' ')<<setw(4)<<' ';-
for(i=0;i<6;i++)-
cout<<setw(3)<<a[i]; //輸出a[6]中的所有數(shù)-
cout<<endl;-
cout<<setfill(' ')<<setw(2)<<' '<<setfill('*') //美化 -
<<setw(22)<<'*'<<endl<<setfill(' ')<<setw(5)<<' ';-
cout<<"今晚的特別號(hào)碼是:"<<endl;-
int t=rand()%16; //隨機(jī)從16個(gè)數(shù)當(dāng)中產(chǎn)生一個(gè)數(shù)賦給t-
while(t==0)-
{-
t=rand()%16; //除去特別號(hào)碼中的0-
}-
cout<<setfill(' ')<<setw(3)<<' '<<setfill('*')-
<<setw(20)<<'*'<<endl<<setfill(' ')<<setw(4)<<' ';-
cout<<setw(9)<<t<<endl;//輸出最后一個(gè)特別號(hào)碼-
cout<<setfill(' ')<<setw(3)<<' '<<setfill('*')<<setw(20) //美化-
<<'*'<<endl<<setfill(' ')<<setw(4)<<' '; -
}-
int fun(int h,int a[1],int i)-
{int k=0;-
while(k<i)-
{-
if(h!=0&&h!=a[k]) k++;-
else return 0;-
}-
return 1;-
}-
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1