[問題] C矩陣問題

看板C_and_CPP作者 (無極限的頭毛)時間10年前 (2014/04/16 21:35), 編輯推噓2(206)
留言8則, 5人參與, 最新討論串1/1
開發平台(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

04/16 21:50, , 1F
你把課本的ld打成1d了
04/16 21:50, 1F

04/16 21:51, , 2F
!!! 原來是這樣... 太感謝了
04/16 21:51, 2F

04/16 21:52, , 3F
你的n被吃到零
04/16 21:52, 3F

04/16 21:53, , 4F
沒事我看錯了
04/16 21:53, 4F

04/16 21:59, , 5F
是scanf("%d",&n); 才對
04/16 21:59, 5F

04/16 22:03, , 6F
阿~~~ 我忘記是long了 卡在這邊卡超久... 謝謝各位的回答
04/16 22:03, 6F

04/16 22:35, , 7F
cout & cin 真的好用很多..
04/16 22:35, 7F

04/16 23:29, , 8F
那是c++的嗎 我沒念過... 現在光念c就一個頭兩個大
04/16 23:29, 8F
文章代碼(AID): #1JJeSs2l (C_and_CPP)