|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
题目要求输出较大的数,但我写的代码他只输出a的值,求路过的大佬帮我看看
#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("max =%d\n",c);
return 0;
}
int max(int x,int y)
{
int z;
if(x > y)z = x;
else z = y;
return (z);
}
这段代码中只输出了变量a的值,这可能是因为在输入时使用了逗号分隔符,而不是空格。修改scanf语句中的逗号为空格,即可正确输入两个变量的值。
修改后的代码如下:
- #include <stdio.h>
- int max(int x, int y);
- int main() {
- int a, b, c;
- scanf("%d %d", &a, &b);
- c = max(a, b);
- printf("max = %d\n", c);
- return 0;
- }
- int max(int x, int y) {
- int z;
- if (x > y) {
- z = x;
- } else {
- z = y;
- }
- return z;
- }
复制代码
另外,建议在if语句中加上花括号,以增加代码的可读性和可维护性。
|
|