標題:
C++語言 福利彩票的中獎號碼
[打印本頁]
作者:
51hei社區(qū)
時間:
2016-1-10 23:27
標題:
C++語言 福利彩票的中獎號碼
本帖最后由 51hei社區(qū) 于 2016-1-10 23:29 編輯
由于格式的問題本程序需要手動去掉每行尾部的-
#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<<"今晚的福利彩票的中獎號碼是:"<<endl;-
-
while(i<6)-
{ h=rand()%33;-
a[i]=h;-
if(fun(h,a,i)) i++; //除去隨機數(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<<"今晚的特別號碼是:"<<endl;-
int t=rand()%16; //隨機從16個數(shù)當中產(chǎn)生一個數(shù)賦給t-
while(t==0)-
{-
t=rand()%16; //除去特別號碼中的0-
}-
cout<<setfill(' ')<<setw(3)<<' '<<setfill('*')-
<<setw(20)<<'*'<<endl<<setfill(' ')<<setw(4)<<' ';-
cout<<setw(9)<<t<<endl;//輸出最后一個特別號碼-
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;-
}-
復制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1