int main() { int max(int x, int y); int a=5, b=8, 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); else z = y; return 0; }
时间: 2023-12-03 21:03:25 浏览: 32
你的代码存在一些问题。首先,在 `max` 函数中,你的条件语句 `if (x > y);` 后面有一个分号,这会导致 `z` 没有被赋值。你需要去掉分号,使得代码变为 `if (x > y) z = x;`。
另外,你的 `max` 函数应该返回 `z` 而不是固定的 `0`。修改后的代码如下:
```c
#include <stdio.h>
int max(int x, int y);
int main()
{
int a = 5, b = 8, 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;
}
```
这样修改后,你应该能够正确地找到输入的两个数中的最大值,并将其打印出来。
希望这可以帮助到你!如有其他问题,请随时提问。
相关问题
#include<stdio.h> int main() { int max(int x,int y); int x,y,z; scanf("%d %d\n",&x ,&y); z=max(x,y); printf("最大=%d\n”,z); } 哪里错了
代码中的第一行应该是 `#include <stdio.h>`,而不是 `#include<stdio.h>`。同时,最后一行的引号应该改为英文引号 `"`, 而不是中文引号 `”`。另外,定义函数 `max` 应该在 `main` 函数之前,或者在 `main` 函数外。修改后的代码如下:
```c
#include <stdio.h>
int max(int x, int y) {
return x > y ? x : y;
}
int main() {
int x, y, z;
scanf("%d %d", &x, &y);
z = max(x, y);
printf("最大=%d\n", z);
return 0;
}
```
这样就可以编译和运行了。
//课程代码3 #include<stdio.h> int Max3(int a,int b,int c); int Max(int a,int b); int main() { int x,y,z,max; scanf("%d%d%d",&x,&y,&z); max = Max3(x,y,z); printf("max=%d\n",max); return 0; } int Max3(int a,int b,int c) { int max; max = Max(a,b); max = Max(max,c); return max; } int Max(int a,int b) { if(a>b) return a; else return b; }帮我注释这段代码
// 题目:使用函数求出三个数中的最大值
#include<stdio.h>
// 定义函数Max3,传入三个参数a,b,c,返回三个数中的最大值
int Max3(int a, int b, int c);
// 定义函数Max,传入两个参数a,b,返回两个数中的最大值
int Max(int a, int b);
// 主函数
int main()
{
// 定义三个整型变量x,y,z,以及变量max
int x, y, z, max;
// 从键盘输入三个整数
scanf("%d%d%d", &x, &y, &z);
// 调用函数Max3,传入x,y,z三个参数,将返回值赋给变量max
max = Max3(x, y, z);
// 输出最大值
printf("max=%d\n", max);
// 返回程序执行成功
return 0;
}
// 定义函数Max3,传入三个参数a,b,c,返回三个数中的最大值
int Max3(int a, int b, int c)
{
// 定义变量max,初始值为a和b中的最大值
int max = Max(a, b);
// 将max和c比较,取其最大值
max = Max(max, c);
// 返回最大值
return max;
}
// 定义函数Max,传入两个参数a,b,返回两个数中的最大值
int Max(int a, int b)
{
// 如果a大于b,返回a,否则返回b
if (a > b)
return a;
else
return b;
}
注释中提供了每个函数的功能和参数,以及变量的定义和程序的流程。同时还包括了代码中的注释,方便阅读和理解代码。
相关推荐
![ppt](https://img-home.csdnimg.cn/images/20210720083527.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)