3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
[C/C++基礎]-猜數字遊戲 本篇要分享猜數字遊戲程式碼,有興趣的(C/P)同好,歡迎來(C/P)一下哈哈 ^ ^。 程式碼 #include #include #include usingnamespace std;   int main() { int a,bit=0; int b[99]; cin>>a; while(a>1){   b[bit]=a%2;   bit++;   a=(int)a/2; }     b[bit]=a; for(int i=bit;i>=0;i--)cout< cout<猜數字"<     srand(time(NULL)); int c[4],d[4],e,ga,gb; for(i=0;i<4;i++)c[i]=rand();     do{      cin>>e;         d[0]=(int)(e/1000);   e-=d[0]*1000;   d[1]=(int)(e/100);   e-=d[1]*100;   d[2]=(int)(e/10);   e-=d[2]*10;   d[3]=e;   ga=0;gb=0;   for(i=0;i<4;i++){    for(int j=0;j<4;j++){     if(d[i]==c[j]){      if(i==j)ga++;else gb++;     }    }   }   cout< }while(d[0]!=c[0]||d[1]!=c[1]||d[2]!=c[2]||d[3]!=c[3]); cout< system("pause"); return 0; }    

本文由jashliaoeuwordpress提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦