標題: C++語言 福利彩票的中獎號碼 [打印本頁]

作者: 51hei社區(qū)    時間: 2016-1-10 23:27
標題: C++語言 福利彩票的中獎號碼
本帖最后由 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++;  //除去隨機數(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;  //隨機從16個數(shù)當中產(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. }-
復制代碼







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1