Powered by Blogger.

Write a shell script to find the sum of the first n numbers.





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"

-------------------------------------------------------------------------------------------------
->OUTPUT:
---------

Enter a number:
5
The sum of first 5 numbers is: 15

*************************************************************************************************
Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment