|
发表于 2024-1-5 21:57:26
|
显示全部楼层
- #include <stdio.h>
- int main()
- {
- int a, b, c, max;
- scanf_s("%d %d %d",&a,&b,&c);
- max = a;
- if (max < b)
- max = b;
- if (max< c);
- max = c;
- printf("最大数为%d", max);
- return 0 ;
- }
复制代码
运行你的代码,有几个错误。
- test.c:6:9: error: call to undeclared function 'scanf_s'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
- scanf_s("%d %d %d",&a,&b,&c);
- ^
- test.c:6:9: note: did you mean 'scanf'?
- /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdio.h:174:6: note: 'scanf' declared here
- int scanf(const char * __restrict, ...) __scanflike(1, 2);
- ^
- test.c:10:20: warning: if statement has empty body [-Wempty-body]
- if (max< c);
- ^
- test.c:10:20: note: put the semicolon on a separate line to silence this warning
- 1 warning and 1 error generated.
复制代码
改进代码!
- #include <stdio.h>
- int main()
- {
- int a, b, c, max;
- scanf("%d %d %d",&a,&b,&c);
- max = a;
- if (max < b)
- max = b;
- if (max< c)
- max = c;
- printf("最大数为%d", max);
- return 0 ;
- }
复制代码
编译结果:
- ➜ Desktop vim test.c
- ➜ Desktop gcc test.c
- ➜ Desktop ./a.out
- 1 2 3
- 最大数为3%
复制代码 |
评分
-
查看全部评分
|