LINUX SEHLL PROGRAM FOR INTERCHANGING TWO NUMBERS WITHOUT VARIABLE | OPERATING SYSTEM (OS) LAB IN LINUX| SWAP WITHOUT VARIABLE |

AIM:
To write a shell program for the following:
(i) interchanging two numbers using temporary variable.
(ii) interchanging two numbers using without temporary variable.
ALGORITHM:
interchanging two numbers using temporary variable:
· Get the two numbers to be swapped.
· Swap them by using the temporary variable.
· Display the value after swapping.

interchanging two numbers using without temporary variable:
· Get the two numbers to be swapped.
· Swap them by without using the temporary variable.
· Display the value after swapping

PROGRAM SOURCE CODE
(i)interchanging two numbers using temporary variable:
echo ”enter a”
read a
echo “enter b”
read b
c = $a
a = $b
b = $c
echo “after swapping”
echo “number a is $a”
echo “number b is $b”


(ii) interchanging two numbers using temporary variable:
echo ”enter a”
read a
echo “enter b”
read b
a=’expr $a + $b'
b=’expr $a - $b'
a=’expr $a - $b'
echo “after swapping”
echo “number a is $a”
echo “number b is $b”
CONCLUSION:
Thus the shell program for interchanging two numbers with and without using temporary variables are written and executed successfully.

Post a Comment

0 Comments