输入3个整数输出其中最大数
时间: 2023-04-09 19:04:40 浏览: 130
我可以回答这个问题。请看以下代码:
```lua
function max(a, b, c)
if a >= b and a >= c then
return a
elseif b >= a and b >= c then
return b
else
return c
end
end
print(max(1, 2, 3)) -- 输出 3
```
这段代码可以输入三个整数,然后输出其中最大的数。
相关问题
输入三个整数输出其中最大的数
好的,可以使用以下的 Python 代码实现:
```python
a = int(input("请输入第一个整数:"))
b = int(input("请输入第二个整数:"))
c = int(input("请输入第三个整数:"))
if a >= b and a >= c:
print("最大的数是:", a)
elif b >= a and b >= c:
print("最大的数是:", b)
else:
print("最大的数是:", c)
```
你可以输入三个整数,程序会输出其中最大的数。
输入两个整数 输出其中最大的数
算法1:if语句比较大小
1. 读入两个整数a和b
2. 如果a>b,则输出a
3. 否则,输出b
时间复杂度:O(1)
Python代码:
```
a = int(input())
b = int(input())
if a > b:
print(a)
else:
print(b)
```
算法2:使用max函数
1. 读入两个整数a和b
2. 使用max函数比较a和b的大小
3. 输出比较结果
时间复杂度:O(1)
Python代码:
```
a = int(input())
b = int(input())
print(max(a, b))
```