# 100以内整数和 #!/bin/sh declare -i SUM=0 for ((i=1;i<=100;i+=1)) do let SUM+=$i done echo $SUM #!/bin/sh declare -i SUM=0 for i in {1..100} do let SUM+=$i done echo $SUM #100以内偶数和 #!/bin/sh declare -i SUM=0 for ((i=2;i<=100;i+=2)) do let SUM+=$i done echo $SUM #100以内奇数和 #!/bin/sh declare -i SUM=0 for ((i=1;i<=100;i+=2)) do let SUM+=$i done echo $SUM
shell使用for循环完成100以内累加,布布扣,bubuko.com
时间: 2024-12-19 01:37:56