找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2539|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

C++語言 福利彩票的中獎號碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:102668 發(fā)表于 2016-1-10 23:27 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本帖最后由 51hei社區(qū) 于 2016-1-10 23:29 編輯

由于格式的問題本程序需要手動去掉每行尾部的-
  1. #include<iostream>-

  2. #include<iomanip>-

  3. #include<time.h>-

  4. using namespace std;-

  5. int fun(int h,int a[],int i);-

  6. void main()-

  7. {int i=1,h,a[6],k=0;-

  8.    srand(time(0));-

  9.    a[0]=rand()%33;-

  10. while(a[0]==0)   //除去a[0]中的0-

  11. { -

  12.     a[0]=rand()%33;-

  13. }-

  14. -

  15. cout<<"今晚的福利彩票的中獎號碼是:"<<endl;-

  16. -

  17. while(i<6)-

  18. {  h=rand()%33;-

  19.    a[i]=h;-

  20.    if(fun(h,a,i)) i++;  //除去隨機(jī)數(shù)中的相同數(shù)-

  21. }-

  22. cout<<setfill(' ')<<setw(2)<<' '<<setfill('*')-

  23.   <<setw(22)<<'*'<<endl;   //美化    -

  24.   cout<<setfill(' ')<<setw(4)<<' ';-

  25. for(i=0;i<6;i++)-

  26.     cout<<setw(3)<<a[i];  //輸出a[6]中的所有數(shù)-

  27.     cout<<endl;-

  28. cout<<setfill(' ')<<setw(2)<<' '<<setfill('*')    //美化                 -

  29. <<setw(22)<<'*'<<endl<<setfill(' ')<<setw(5)<<' ';-

  30. cout<<"今晚的特別號碼是:"<<endl;-

  31. int t=rand()%16;  //隨機(jī)從16個數(shù)當(dāng)中產(chǎn)生一個數(shù)賦給t-

  32. while(t==0)-

  33. {-

  34. t=rand()%16;    //除去特別號碼中的0-

  35. }-

  36. cout<<setfill(' ')<<setw(3)<<' '<<setfill('*')-

  37.     <<setw(20)<<'*'<<endl<<setfill(' ')<<setw(4)<<' ';-

  38. cout<<setw(9)<<t<<endl;//輸出最后一個特別號碼-

  39. cout<<setfill(' ')<<setw(3)<<' '<<setfill('*')<<setw(20)  //美化-

  40.     <<'*'<<endl<<setfill(' ')<<setw(4)<<' ';                  -

  41. }-

  42. int fun(int h,int a[1],int i)-

  43. {int k=0;-

  44. while(k<i)-

  45. {-

  46. if(h!=0&&h!=a[k]) k++;-

  47. else return 0;-

  48. }-

  49. return 1;-

  50. }-
復(fù)制代碼


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表