【问题标题】:why is my code not giving the proper output?Can anyone provide a hint?为什么我的代码没有给出正确的输出?谁能提供提示?
【发布时间】:2021-10-06 12:48:45
【问题描述】:

所以基本上我写了这段代码来打印更大的数字,但它不起作用。我是 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;
    
}```

【问题讨论】:

    标签: c function


    【解决方案1】:

    问题是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?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-19
      • 2018-02-27
      • 1970-01-01
      • 2021-08-24
      • 2018-10-28
      • 2020-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多