使用for循环:
#!/bin/sh
#a:the start num b:the end num
#Calculates the sum of all integers between two Numbers
#a<b
read -p 'please input the starting num:' a
read -p 'please input the end num:' b
for i in `seq $a $b`
do
sum=$[$sum+$i];
done
echo $sum

本文介绍了一种使用Shell脚本通过for循环来计算两个指定数字之间所有整数之和的方法。用户将被提示输入起始和结束数字,脚本将输出这一范围内的整数总和。
2538

被折叠的 条评论
为什么被折叠?



