# Answers for "swap two numbers without using third variable"

4

swap 2 numbers without using 3rd variable

``````a=10;
b=20;
a=a+b;//a=30 (10+20)
b=a-b;//b=10 (30-20)
a=a-b;//a=20 (30-10)``````
Posted by: Guest on May-16-2021
1

swap two variables without temporary java

``````import java.*;

class noTemp {

public static void main(String a[])
{
int x = 10;
int y = 5;
x = x + y;
y = x - y;
x = x - y;
System.out.println("After swaping:"
+ " x = " + x + ", y = " + y);
}
}``````
Posted by: Guest on January-22-2021
1

swapping without third variable use

``````x = x + y
y = x - y
x = x - y``````
Posted by: Guest on June-10-2021
2

swap without using third variable

``````// SWAPPING WITHOUT USING THIRD VARIABLE
#include<stdio.h>
int main()
{
int a=10, b=20;
printf("Before swap a=%d b=%d",a,b);
a=a+b;//a=30 (10+20)
b=a-b;//b=10 (30-20)
a=a-b;//a=20 (30-10)
printf("\nAfter swap a=%d b=%d",a,b);
return 0;
}   ``````
Posted by: Guest on March-03-2021
1

Write a program to show swap of two numbers without using third variable.

``````#include<stdio.h>
int main()
{
int a=10, b=20;
printf("Before swap a=%d b=%d",a,b);
a=a+b;//a=30 (10+20)
b=a-b;//b=10 (30-20)
a=a-b;//a=20 (30-10)
printf("\nAfter swap a=%d b=%d",a,b);
return 0;
}``````
Posted by: Guest on February-02-2021
0

swap two numbers without using third variable

``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);``
Posted by: Guest on June-28-2021