我只想要一個程序,用戶輸入a和b的值,並會問如果值a小於b,則用戶重複此過程。 這裏是我的程序:我剛剛開始學習循環在C編程,並試圖創建一個簡單的程序來測試我的知識,但它不會工作
#include <stdio.h>
#include <math.h>
int main(void)
{
int a, b ,c;
while (a<=b)
{
printf("Please enter a value for a:\n");
scanf("%d", &a);
printf("Please enter a value for b:\n");
scanf("%d", &b);
if (a<=b)
printf("a must be greater than b:\n");
}
c=a+b;
printf("The answer of c is: %d\n", c);
return 0;
}
我只要一運行程序,它打印:「C的答案是:1829030」 (請注意,最後一個數字始終是隨機的)
請幫我運行這個程序。
解釋謝謝! 但是我用程序沒有聲明a和b的值和程序的工作。你能解釋一下當你應該用值來聲明這些嗎? –
請在SO上閱讀其他答案:http://stackoverflow.com/questions/4532871/define-integer-int-whats-the-default-value –