Showing posts with label Swapping values of two variables. Show all posts
Showing posts with label Swapping values of two variables. Show all posts

Thursday, March 5, 2015

Swapping values of two variables

Algorithm
Step 1 : Start
Step 2 : Read the values of a and b
Step 3 : Interchange the values of a and b using another variable t as follows:
t = a
a = b
b = t
Step 4 : Print a and b
Step 5 : Stop

Program (swap.sh)
# Swapping values
echo -n "Enter value for A : "
read a
echo -n "Enter value for B : "
read b
t=$a
a=$b
b=$t
echo "Values after Swapping"
echo "A Value is $a"
echo "B Value is $b"