注册 登录
编程论坛 C语言论坛

求两个整数中较大者,运行就出错

moluozi 发布于 2020-12-22 20:51, 1760 次点击
新手,照着书敲的,为啥一运行就提示错误呢,求解啊!谢谢。
程序代码:
#include <stdio.h>
int main( )
{
    int max(int x, int y);
    int a, b, c;
    scanf("%d,%d", &a, &b);
    c = max(a, b);
    printf("zuidazhi=%d\n",c);
    return 0;
}
int max(int x, int y);
{
    int z;
    if (x > y)z = x;
    else z = y;
    return(z);
}


错误提示
1>------ 已启动生成: 项目: ConsoleApplication1, 配置: Debug Win32 ------
1>  2.c
1>e:\cdemo\consoleapplication1\consoleapplication1\2.c(6): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>  c:\program files (x86)\windows kits\10\include\10.0.10150.0\ucrt\stdio.h(1270): note: 参见“scanf”的声明
1>e:\cdemo\consoleapplication1\consoleapplication1\2.c(12): error C2449: 在文件范围内找到“{”(是否缺少函数头?)
1>e:\cdemo\consoleapplication1\consoleapplication1\2.c(17): error C2059: 语法错误:“}”
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
3 回复
#2
memcpy2020-12-22 21:17
函数写在main下面时  要先声明呀
#3
rjsp2020-12-22 22:30
程序代码:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int max(int x, int y);

int main( void )
{
    int a, b;
    scanf( "%d ,%d", &a, &b);
   
    int c = max(a, b);
    printf( "zuidazhi=%d\n", c );
   
    return 0;
}
int max(int x, int y)
{
    return x>y ? x : y;
}


输入
3, 5

输出
zuidazhi=5
#4
do8do8do82020-12-23 00:15
多了个;号
1