SWAPPING OF VALUES
(Without using 3rd Variable)
To
write a Shell Program to swap two values without using 3rd Variable.
ALGORITHM:
Step 1: Start
Step 2: Read the values of ‘a’ and ‘b’
Step 3: Solve the expression, a=a + b; b=a – b; a=a – b
Step 4: Print the swapped values of ‘a’ and ‘b’
Step 5: Stop
SHELL
PROGRAM:
echo "Enter Two Numbers"
read a b
a=`expr $a + $b`
b=`expr $a - $b`
a=`expr $a - $b`
echo $a $b
SAMPLE
OUTPUT:
Enter Two Numbers
12 10
10 12
RESULT:
Thus
the Shell Program to swap two values without using third variable was executed
and the output was verified.
No comments:
Post a Comment