编写一个程序,读入三个整数,然后确定并打印该组中最大和最小的整数。
时间: 2024-05-09 19:18:37 浏览: 10
下面是一个 Python 代码示例:
```python
num1 = int(input("请输入第一个整数:"))
num2 = int(input("请输入第二个整数:"))
num3 = int(input("请输入第三个整数:"))
max_num = max(num1, num2, num3)
min_num = min(num1, num2, num3)
print("最大的整数是:", max_num)
print("最小的整数是:", min_num)
```
示例输出:
```
请输入第一个整数:8
请输入第二个整数:-3
请输入第三个整数:5
最大的整数是: 8
最小的整数是: -3
```
相关问题
用c++编写以下程序:任意读入三个整数,然后按从小到大的顺序输出这三个数
以下是程序代码:
```c
#include <stdio.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a > b) {
int temp = a;
a = b;
b = temp;
}
if (a > c) {
int temp = a;
a = c;
c = temp;
}
if (b > c) {
int temp = b;
b = c;
c = temp;
}
printf("%d %d %d\n", a, b, c);
return 0;
}
```
这个程序可以读入三个整数,然后按从小到大的顺序输出这三个数。
编写一个程序,输入3个非0的整数,判断并打印出这些值能否构成三角形的三边
可以回答。以下是一个 Python 的实现:
```
a = int(input("请输入第一个整数:"))
b = int(input("请输入第二个整数:"))
c = int(input("请输入第三个整数:"))
if a + b > c and a + c > b and b + c > a:
print("可以构成三角形")
else:
print("不能构成三角形")
```
这个程序会先读入三个整数,然后判断它们是否能构成三角形。如果能,就输出"可以构成三角形",否则输出"不能构成三角形"。
相关推荐
![](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)