echo "Enter a number: "
read num
i=1
sum=0
while [ $i -le $num ]
do
sum=`expr $sum + $i`
i=`expr $i + 1`
done
echo "The sum of first $num numbers is: $sum"
--------------------------------------------------------------------------------------------------------------
Enter a number:
5
The sum of first 5 numbers is: 15
0 comments:
Post a Comment