编写程序求 1-3+5-7+.--99+101 的值。 3. 从键盘输入三个整数,比较三个数并显示
时间: 2023-05-22 12:06:22 浏览: 95
答案:
1. 这个程序可以用 Python 语言编写,代码如下:
```
result = 0
for i in range(1, 102, 2):
if i == 99:
continue
result += i
print(result)
```
2. 以下是中文加密和 Lua 闭包工厂的代码示例:
中文加密:
```lua
function encrypt(str)
local result = ""
for i = 1, #str do
local char = string.sub(str, i, i)
local ascii = string.byte(char)
result = result .. tostring(ascii)
end
return result
end
```
Lua 闭包工厂:
```lua
function createClosureFactory()
local count = 0
return function()
count = count + 1
return count
end
end
closureFactory = createClosureFactory()
print(closureFactory())
print(closureFactory())
```
3. 以下是比较三个整数的程序示例:
```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)
```
阅读全文