我只想要一个程序,用户输入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 –