輸入二進位換成十進位 (看不出哪裡錯了)




立即點擊


偵錯過後都沒問題但不知是logic錯了還是別的~~出來的數字不正確甚至有負的??程式碼:#include#includeusingnamespacestd;intinteger;intmain(){intinteger;cout<<"pleaseenteranintegercontainingonly0sans1s:"<>integer;inta=1;intb=1;inttotal=0;int...顯示更多偵錯過後都沒問題但不知是logic錯了還是別的~~出來的數字不正確甚至有負的??程式碼:#include#includeusingnamespacestd;intinteger;intmain(){intinteger;cout<<"pleaseenteranintegercontainingonly0sans1s:"<>integer;inta=1;intb=1;inttotal=0;intsum;intc=1;while(integer/a>0){(integer/a)*b==sum;a=a*10;c=c*10;b=b*2;total=totalsum;1}cout<




老師有規定一定要輸入數值嗎? 輸入的2進位 00111010.. 應該要用輸入字串寫吧 不然用你的int定義 像111111這樣的值早爆了好不好 (int範圍才3萬多,6個1就十幾萬) 正常寫法: 輸入01字串後,再反轉字串,再取出字元,再累計2^N次方吧 以下是配合你那種寫法的程式: ---------------------------------------------------------------------------------- #include #include int main() { int integer; int a,b=1; int total=0; cout<<"please enter an integer containing only 0s ans 1s: "<>integer; while (integer> 0) { a=integer%10; integer=integer/10; total=total+a*b; b=b*2; } cout<




c++語法皆可盡量使用while一定要用這方法嗎??在輸出時用特定語法可以嗎??


以上文章來自奇摩知識家,如有侵犯請留言告知


https://tw.answers.yahoo.com/question/index?qid=20051030000014KK01017

9D1C50A44D654017
arrow
arrow
    創作者介紹
    創作者 柯文哲處理 的頭像
    柯文哲處理

    柯文哲處理吳音寧已成攻城困局 柯文哲處理吳音寧已成攻城困局

    柯文哲處理 發表在 痞客邦 留言(0) 人氣()