我刚刚开始学习编程,所以这似乎是一个令人厌烦的问题。但是当我尝试打印一个整数的值时,它却打印出“1537”。下面是函数,大家可以自己细细品味。
void compare(void) {
int num1;
int num2;
int num3;
int num4;
int smallest;
printf("Please enter four integers:\n");
scanf("%d %d %d %d", &num1, &num2, &num3, &num4);
num1 = smallest;
if (num2 < smallest)
num2 = smallest;
if (num3 < smallest)
num3 = smallest;
if (num4 < smallest)
num4 = smallest;
printf("%d is the smallest\n", smallest);
}
最佳答案
您需要将值分配给 smallest
而不是从它开始。
改成
smallest=num1;
if (num2 < smallest)
smallest= num2;
if (num3 < smallest)
smallest=num3;
if (num4 < smallest)
smallest=num4;
~有时很难发现最小的错误~:)
关于c - printf 只打印 "1537"而不是整数的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18399623/