Closed. This question is off-topic. It is not currently accepting answers. Learn more。
想改进这个问题吗?Update the question所以堆栈溢出的值小于aa>。
我用%来确定数字是否可以被5整除。但它似乎总是返回“0”,表示所有内容都可以被5整除。
我做错什么了?
#!/bin/sh
n=20
i=1
# loop while i <= n
while [ $i -lt $n ] || [ $i -eq $n ]
do
# find the numbers that are evenly divisible by '5'
m=`expr $n % 5`
if [ $m -eq 0 ]; then
echo $i" is evenly divisible by 5"
fi
# do i = i + 1
i=`expr $i + 1`
done
我的输出如下:
1 is evenly divisible by 5
2 is evenly divisible by 5
3 is evenly divisible by 5
4 is evenly divisible by 5
5 is evenly divisible by 5
6 is evenly divisible by 5
7 is evenly divisible by 5
8 is evenly divisible by 5
9 is evenly divisible by 5
10 is evenly divisible by 5
11 is evenly divisible by 5
12 is evenly divisible by 5
13 is evenly divisible by 5
14 is evenly divisible by 5
15 is evenly divisible by 5
16 is evenly divisible by 5
17 is evenly divisible by 5
18 is evenly divisible by 5
19 is evenly divisible by 5
20 is evenly divisible by 5
最佳答案
n始终为20,因此“m=`expr$n%5”将始终为0
10-07 16:23