看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) Win10 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) dev c++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 執行問題 餵入的資料(Input): 輸入兩個數字 ex:4 12 預期的正確結果(Expected Output): 1 2 4 錯誤結果(Wrong Output): 沒有跑出東西 程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔) #include<stdio.h> #include<stdlib.h> int main() { int a,b,i; printf("請由小到大輸入兩個數字,系統將取出兩數字的公因數”); scanf("%d%d,&a,&b"); for(i=0;i<=a;i++) if(a%i==0&&b%i==0) printf("%d ",i); system("pause); return 0; 補充說明(Supplement): 想問各位我這個程式那邊的邏輯出現問題呢? 希望各位可以稍微給我一點想法 詳細的程式我會自己下去實作的 因為剛開始接觸程式所以還有很多東西不懂 還請各位見晾 先謝過各位了! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.217.196.59 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1566050065.A.3BC.html ※ 編輯: td2100106 (180.217.196.59 臺灣), 08/17/2019 21:56:20 ※ 編輯: td2100106 (180.217.196.59 臺灣), 08/17/2019 21:56:57
cutekid: for(i=1;i<=a;i++) 08/17 21:59
arfa0711: 感覺for迴圈{要包住printed}小弟菜 請多指教 08/17 22:02
nh60211as: 數字不能除以0(a%0) 08/17 22:10
idiont: scanf("%d%d"&a,&b); 08/17 22:10
idiont: idiont: scanf("%d%d",&a,&b); 08/17 22:10
idiont: system("pause"); 08/17 22:11
idiont: 前面id是複製推文忘記刪掉的 不要理他 08/17 22:12
nickchen1202: {}跟()很重要滴 08/17 23:32
dces4212: i從1開始,0會觸發trap,在Linux會直接exception,沒Win 08/18 02:16
dces4212: dows不知道結果如何,應該是差不多,i從1開始就好 08/18 02:16
dces4212: 快睡著== 最後一句多打請無視xd 08/18 02:17
dces4212: 另外就是scanf問題,如i大所述 08/18 02:18
dces4212: 然後迴圈那邊沒有大括號也可以有預期結果,因為沒括號預 08/18 02:19
dces4212: 設只做往下做**一**行,再下一行就不算在迴圈內了 08/18 02:20
dces4212: 可是為了好讀還是建議加個括號或是indention 08/18 02:21
dces4212: 阿再補充一下 for往下後遇到if所以還可以再往下做一行 08/18 02:24
wl00887404: 建議裝一下 code formater 有自動縮排可以減少 syntax 08/31 09:20
wl00887404: error 的問題 08/31 09:20