好吧,這可能很簡單,我很可能會被你罵,但我是新來的c,並試圖儘可能地學習。我有這個問題,我解決了,而且邏輯工作相當不錯。但是每當有錯誤的輸入,它顯示屏幕上的消息,並加上條件是不正確的。因此,無論何時應該有一個無效的輸入消息,我也得到NE - 至極就是它會打印出來,如果病情心不是true.This是代碼:printf中的輸出錯誤
#include <stdio.h>
#include <stdlib.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
if(a <= 0 || b <= 0) {
printf("Invalid input");
} else {
if(a < b) {
int tmp = a;
a = b;
b = tmp;
}
}
a/=10;
int c1,c2;
while (a!=0 && b!=0){
c1 = a%10;
c2 = b%10;
a /= 100;
b /= 10;
}
if (c1 == c2)
printf("PAREN\n");
else
printf ("NE\n");
return 0;
}
爲什麼''printf(「Invalid input」)之後'返回1';'?這樣它就不會打印'NE'。 – Linus
我不是100%確定有效輸入是什麼,爲什麼產生的輸出是PAREN或NE? – Mike
爲了表明問題已解決,您應該點擊對您有幫助的答案左側的複選標記。 – user3386109