c语言函数三个数比大小
时间: 2023-09-29 10:09:37 浏览: 46
可以编写一个函数,接收三个参数,比较它们的大小,并返回最大值。代码如下:
```
#include <stdio.h>
int max(int a, int b, int c) {
int max = a;
if (b > max) {
max = b;
}
if (c > max) {
max = c;
}
return max;
}
int main() {
int a = 10, b = 20, c = 30;
printf("最大值为:%d\n", max(a, b, c));
return 0;
}
```
运行结果:
```
最大值为:30
```
相关问题
c语言三个数比大小代码
以下是一个用 C 语言编写的比较三个数大小的代码示例:
```c
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数:\n");
scanf("%d %d %d", &a, &b, &c);
if (a > b && a > c) {
printf("%d 是最大的数\n", a);
}
else if (b > a && b > c) {
printf("%d 是最大的数\n", b);
}
else if (c > a && c > b) {
printf("%d 是最大的数\n", c);
}
else {
printf("输入的三个数存在相等的情况\n");
}
return 0;
}
```
上述代码首先使用 `scanf` 函数从用户处获取三个整数。然后通过一系列的条件语句(`if-else if-else`)来比较这三个数的大小,并输出最大的数。如果三个数中有两个或更多个数相等,则输出存在相等的情况。
c语言中输入三个数比大小
以下是一个简单的C程序,用于输入三个数字并比较它们的大小:
```
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数:\n");
scanf("%d %d %d", &a, &b, &c);
if (a > b && a > c) {
printf("%d 是最大的数。\n", a);
} else if (b > a && b > c) {
printf("%d 是最大的数。\n", b);
} else {
printf("%d 是最大的数。\n", c);
}
return 0;
}
```
该程序首先提示用户输入三个整数,然后使用scanf函数将它们读入变量a、b和c中。接下来,使用if语句比较这些数字,并输出最大的数字。如果两个或三个数字相等,那么程序将输出其中任何一个数字。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)