编写一个Application程序:字给定一个正整数 n,统计比 n 小的不能被7整除的正整数个数,输出格式:n前面共有xx个不能被7。
时间: 2023-04-09 16:04:18 浏览: 101
好的,这是一个编程类的问题,我可以回答。以下是Lua语言的代码实现:
```lua
function count(n)
local cnt = 0
for i = 1, n-1 do
if i % 7 ~= 0 then
cnt = cnt + 1
end
end
return cnt
end
local n = 100
local cnt = count(n)
print(n .. "前面共有" .. cnt .. "个不能被7整除的正整数")
```
输出结果为:
```
100前面共有85个不能被7整除的正整数
```
希望能够帮到您!
相关问题
编写一个Application程序:字给定一个正整数 n,统计比 n 小的不能被7整除的正整数个数。 输出格式:n前面共有xx个不能被7。
好的,让我来回答你的问题。这是一个编程类的问题,可以回答。以下是一个简单的应用程序,可以统计比给定正整数 n 小的不能被 7 整除的正整数个数:
```python
def count_numbers(n):
count = 0
for i in range(1, n):
if i % 7 != 0:
count += 1
return count
n = int(input("请输入一个正整数:"))
print("在", n, "之前有", count_numbers(n), "个不能被7整除的正整数。")
```
你可以将这段代码保存为一个 Python 文件,然后在命令行中运行它,输入一个正整数 n,程序将输出比 n 小的不能被 7 整除的正整数个数。
希望这个回答能够帮到你!
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![text/x-c++](https://img-home.csdnimg.cn/images/20250102104920.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)