Program to swap two numbers without using the third variable
Program to swap two number without using third variable.Most asked question in interview.
Jun 28, 2021
Program using JavaScript
var a=window.prompt('enter a number')
var b=window.prompt('enter a number')
var a=a+b;
var b=a-b;
var a=a-b;
console.log ("value of a is",a);
console.log('value of b is',b);
Algorithm
Step 1: Start
Step 2: Enter two numbers a and b
Step 3: Print a, b
Step 4: a= a+b
Step 5: b= a-b
Step 6: a= a-b
Step 7: End
Output
enter a number a and b : 10,20
Before Swapping :10,20
After Swapping :20,10