输入三个数求最大值最小值中间数
时间: 2023-05-31 16:04:53 浏览: 154
请问您需要用什么编程语言实现这个功能呢?以下是Python的实现示例:
```python
# 输入三个数
a = float(input("请输入第一个数:"))
b = float(input("请输入第二个数:"))
c = float(input("请输入第三个数:"))
# 求最大值、最小值和中间数
max_num = max(a, b, c)
min_num = min(a, b, c)
mid_num = a + b + c - max_num - min_num
# 输出结果
print("最大值为:", max_num)
print("最小值为:", min_num)
print("中间数为:", mid_num)
```
运行结果:
```
请输入第一个数:2
请输入第二个数:1
请输入第三个数:3
最大值为: 3.0
最小值为: 1.0
中间数为: 2.0
```
相关问题
用C输入三个数求最大值最小值中间数
以下是用C语言实现输入三个数求最大值、最小值和中间数的代码:
```c
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数:");
scanf("%d%d%d", &a, &b, &c);
int max = a, min = a, mid;
if (b > max) max = b;
if (c > max) max = c;
if (b < min) min = b;
if (c < min) min = c;
if (a != max && a != min) mid = a;
else if (b != max && b != min) mid = b;
else mid = c;
printf("最大值:%d\n", max);
printf("最小值:%d\n", min);
printf("中间数:%d\n", mid);
return 0;
}
```
运行结果:
```
请输入三个整数:5 8 3
最大值:8
最小值:3
中间数:5
```
三个值输出最大值最小值中间值的程序
以下是Python实现的一个简单程序:
```python
a = int(input("请输入第一个数:"))
b = int(input("请输入第二个数:"))
c = int(input("请输入第三个数:"))
# 求最大值
if a >= b and a >= c:
max_num = a
elif b >= a and b >= c:
max_num = b
else:
max_num = c
# 求最小值
if a <= b and a <= c:
min_num = a
elif b <= a and b <= c:
min_num = b
else:
min_num = c
# 求中间值
if a != max_num and a != min_num:
mid_num = a
elif b != max_num and b != min_num:
mid_num = b
else:
mid_num = c
print("最大值为:", max_num)
print("最小值为:", min_num)
print("中间值为:", mid_num)
```
程序首先通过`input()`函数获取三个数,然后使用一系列的`if`语句来判断最大值、最小值和中间值。最后,程序将这三个值输出到屏幕上。
阅读全文
相关推荐
![text/x-c++; charset=iso-8859-1](https://img-home.csdnimg.cn/images/20250102104920.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)