Write a program to interchange 2 variables without using the third one.

Showing Answers 1 - 15 of 15 Answers

Gopika

  • Oct 4th, 2005
 

a = a+b;

b = a-b;

a = a-b;

For ex,  let us assume a = 5 and b = 10

a = a+b = 15;

b = a-b = 5;

a = a-b = 10;

  Was this answer useful?  Yes

Ashutosh

  • Nov 7th, 2005
 

a = (a + b) - (b = a);

laksh

  • Apr 20th, 2006
 

int a=10,b=20;

a=a+b;

b=a^b;

a=a^b;

  Was this answer useful?  Yes

heera lal

  • Jun 26th, 2009
 

#include<stdio.h>
#include<conio.h>
void main
{

int a,b;
printf("enter the two no");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("a=%d,b=%d",a,b);
getch();
}

  Was this answer useful?  Yes

dhruv sood

  • Nov 5th, 2012
 

with output

  Was this answer useful?  Yes

bhanu

  • May 28th, 2014
 

x=x*y;
y=x/y;
x=x/y;


  Was this answer useful?  Yes

Ankesh Singh

  • Sep 18th, 2014
 

x = x+y;
y = x-y;
x = x-y;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions