Saturday, 16 March 2013

CPL Exp.No.7b for OBS


Exp.No.7b – SUM OF FIVE NUMBERS FROM COMMAND LINE



Coding

# Read N numbers from the user with command line argument and display its sum
if [ $#  -eq 0 ]
then
echo "Enter the arguments properly" fi
sum=0;
n=$#
for i in $*
do
sum=`expr $sum + $i`
shift done
if [ $n -ne 0 ]
then echo "The sum of $n number(s) is $sum" fi

No comments:

Post a Comment