Wednesday, 17 April 2019

Write a shell script to print sum of all even numbers from 1 to 10.


Write a shell script to print sum of all even numbers from 1 to 10.

Script:
echo enter limit

read n
i=2
while [ $i -lt $n ]
do
sum=$((sum+i))
i=$((i+2))
done
echo $sum.

Output
[root@localhost shell_script]# bash sumofevenno.sh
enter limit
10
20.

No comments:

Post a Comment