编写一个Shell,求100以内偶数的和。

#!/bin/bash

echo "Compute the sum of the even number which between 1 and 100..."
SUM=0
for i in $(seq 100)
do 
if [ $((i%2)) == 0 ];
then
    ((SUM+=i))
fi
done
echo "The result is $SUM"

参照原文:https://blog.csdn.net/muyanmoyang/article/details/48136945

posted @ 2021-04-28 17:37  电脑程序爱好者  阅读(1478)  评论(0)    收藏  举报