我刚刚学习编程,所以这似乎是一个令人厌烦的问题.但是当我尝试打印整数的值时,它会打印"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);
}
Run Code Online (Sandbox Code Playgroud)
Van*_*esh 13
你需要分配值smallest而不是它.
将其更改为
smallest=num1;
if (num2 < smallest)
smallest= num2;
if (num3 < smallest)
smallest=num3;
if (num4 < smallest)
smallest=num4;
Run Code Online (Sandbox Code Playgroud)
〜有时候很难抓到最小的错误〜:)
| 归档时间: |
|
| 查看次数: |
120 次 |
| 最近记录: |