Friday, 12 December 2014

Shell Script for Swapping two numbers

Write a Shell Script to Swap the two number

Solution:

echo Enter the two numbers 
read a b
if test $a -gt $b
then
a=`expr $a - $b`
b=`expr $a + $b`
a=`expr $b - $a`
else
b=`expr $b - $a`
a=`expr $a + $b`
b=`expr $a - $b`
fi
echo Swapped Value: $a and $b

Execution:


No comments:

Post a Comment