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"
Output
[vijai@localhost simple]$ sh swap.sh
Enter value for A : 12
Enter value for B : 23
Values after Swapping
A Value is 23
B Value is 12
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"
Output
[vijai@localhost simple]$ sh swap.sh
Enter value for A : 12
Enter value for B : 23
Values after Swapping
A Value is 23
B Value is 12
No comments:
Post a Comment