所以基本上我写了这段代码来打印更大的数字,但它不起作用。我是 C 的新手,这让我很困惑
#include <stdio.h>
int greater(int a, int b);
int main()
{
int a,b,x;
printf("\n Enter two numbers:");
scanf("%d %d ",&a, &b);
x=greater(a, b);
printf("\n The greatest number is:%d", x);
return 0;
}
int greater(int x, int y)
{ int great;
if(x>y){
great=x;
}
else
{
great=y;
}
return great;
}```
答案 0 :(得分:2)
问题是scanf
中的尾随空格,切换到:
printf("\n Enter two numbers:");
scanf("%d %d",&a, &b);
x=greater(a, b);
了解原因:What is the effect of trailing white space in a scanf() format string?