編寫一個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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM