请问一下我的代码有什么错误之处,我该如何去改正?代码如下,编译器的报错在后面的一段

#include <stdio.h>
int main()
{    
    int a,b,c;
    int max(int x,int y)
    scanf("%d%d",a,b);
    printf("你输入的数为%d%d",a,b);
    c = max(a,b);
    printf("max=%d",c);
    return 0;
}
int max(int x,int y)
{
    
    if (x>y)
        return x;
    else         
        return y;

 

 

main.c: In function ‘max’:
main.c:9:2: error: expected declaration specifiers before ‘scanf’
    9 |  scanf("%d%d",a,b);
      |  ^~~~~
main.c:10:2: error: expected declaration specifiers before ‘printf’
   10 |  printf("你输入的数为%d%d",a,b);
      |  ^~~~~~
main.c:11:2: error: expected declaration specifiers before ‘c’
   11 |  c = max(a,b);
      |  ^
main.c:12:2: error: expected declaration specifiers before ‘printf’
   12 |  printf("max=%d",c);
      |  ^~~~~~
main.c:13:5: error: expected declaration specifiers before ‘return’
   13 |     return 0;
      |     ^~~~~~
main.c:14:1: error: expected declaration specifiers before ‘}’ token
   14 | }
      | ^
main.c:18:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
   18 | {
      | ^
main.c: In function ‘main’:
main.c:23:3: error: expected declaration or statement at end of input
   23 |   return y;
      |   ^~~~~~


 

直接的错误有两个:

1、函数声明少了一个分号;

int max(int x,int y);

2、输入语句应该这样:

scanf("%d%d",&a,&b);

不过,一般这样写比较好:

#include<stdio.h>
int max(int,int);

int main(){
    int a,b,c;
    printf("请输入两个整数:\n");
    scanf("%d%d",&a,&b);
    c = max(a,b);
    printf("%d和%d之间的最大值为:%d.\n",a,b,c);	
    return 0;
}

int max(int m,int n){
	return (m>n)?m:n;
}

 

您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

非常感谢您使用有问必答服务,为了后续更快速的帮您解决问题,现诚邀您参与有问必答体验反馈。您的建议将会运用到我们的产品优化中,希望能得到您的支持与协助!

速戳参与调研>>>https://t.csdnimg.cn/Kf0y

C和C++完整教程:https://blog.csdn.net/it_xiangqiang/category_10581430.html