看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) dev c++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 關於課本上面的範例,check a number for repeated digits 程式碼為 #include <stdbool.h> #include <stdio.h> int main (void) { bool digit_seen[10] = {false}; int digit; long n; printf("enter number:"); scanf("%1d", &n); while (n > 0) { digit = n % 10; if(digit_seen[digit]) break; digit_seen[digit] = true; n /= 10; } if (n > 0) printf("repeated digit\n"); else printf("no repeated digit\n") return 0; } 我完全照著打,可是結果是不管輸入甚麼數字進去,輸出的結果都是no repeated digit..orz 不知道問題出在哪邊,請板友幫幫忙qwq -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.37.225.24 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1397655350.A.0AF.html
purincess:你把課本的ld打成1d了 04/16 21:50
a9041208:!!! 原來是這樣... 太感謝了 04/16 21:51
calqlus:你的n被吃到零 04/16 21:52
calqlus:沒事我看錯了 04/16 21:53
Testarosa:是scanf("%d",&n); 才對 04/16 21:59
a9041208:阿~~~ 我忘記是long了 卡在這邊卡超久... 謝謝各位的回答 04/16 22:03
diabloevagto:cout & cin 真的好用很多.. 04/16 22:35
a9041208:那是c++的嗎 我沒念過... 現在光念c就一個頭兩個大 04/16 23:29