Write the algorithm and flowchart to swap two numbers using temporary variable
Answers
1:start.
2:read a,b,temp.
3.temp=a;
a=b;
b=temp;
4:print a,b.
5:stop
for flow chart use
oval shape for stop and start
rectangle for 3rd step
parrelogram for print and read
all should joined by arrows
The Algorithm for swapping two numbers using a temporary variable is,
*numbering represents the steps
- Begin
- Read X and Y
- Show X and Y
- Store X to C ; C = X
- Transfer Y to X ; X = Y
- Transfer C to Y ; Y = C
- Show X and Y
- End
The Flowchart for the above problem is,
Start
║
∨
Read X and Y
║
∨
C=X;
X=Y;
Y=C;
║
∨
Print X and Y
║
∨
Stop