How to swap two variables, without using third variable ?

Answers were Sorted based on User's Feedback



How to swap two variables, without using third variable ?..

Answer / arindam

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

Is This Answer Correct ?    0 Yes 1 No

How to swap two variables, without using third variable ?..

Answer / shruti dengre

answer no. 6th is is correct

Is This Answer Correct ?    0 Yes 1 No

How to swap two variables, without using third variable ?..

Answer / suseela

for ex x=10,y=20
x=x+y=30(i.e 10+20)
y=x-y=10(i.e 30-20)
x=x-y=20(i.e 30-10)

Is This Answer Correct ?    0 Yes 1 No

How to swap two variables, without using third variable ?..

Answer / shubham

#include<stdio.h>
#imclude<conio.h>
main()
{
int a,b;
printf("enter two number");
scanf("%d%d",&a,&b);
b=a-b;
a=a-b;
b=a+b;
printf("after swaping &d",swap);
getch();
}

Is This Answer Correct ?    0 Yes 1 No

How to swap two variables, without using third variable ?..

Answer / lokesh

a=a-b;
b=a-b;
a=a+b;

Is This Answer Correct ?    0 Yes 1 No

How to swap two variables, without using third variable ?..

Answer / praveen kumar telluri

b=a*b/(a=b);

Is This Answer Correct ?    0 Yes 1 No

How to swap two variables, without using third variable ?..

Answer / naveen

Using a single line statement:

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

Is This Answer Correct ?    0 Yes 1 No

How to swap two variables, without using third variable ?..

Answer / hamsa

a=a+b;
b=a-b;
a=a-b;

ex a=2, b=4

a=2+4
b=6-4
a=6-2


ANS a=4
b=4

Is This Answer Correct ?    0 Yes 1 No

How to swap two variables, without using third variable ?..

Answer / debjyoti talukder

a=a+b;
if(a>b)//only the smaller can b subtracted from greater...
b=a-b://...reverse is not possible
else
b=b-a;
a=a-b;

Is This Answer Correct ?    0 Yes 1 No

How to swap two variables, without using third variable ?..

Answer / swapnil r

Swapping two variables

1. #define SWAP(x,y) x^=y^=x^=y

2. a=a+b;
b=a-b;
a=a-b;

3. use xor to swap

a = a^b
b= a^b
a= a^b
4. a=a*b;
b=a/b;
a=a/b;

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More C Code Interview Questions

Write a routine that prints out a 2-D array in spiral order

3 Answers   Microsoft,


how can i search an element in an array

2 Answers   CTS, Microsoft, ViPrak,


WAP to display 1,2,3,4,5........N

2 Answers  


main() { int i=10; void pascal f(int,int,int); f(i++,i++,i++); printf(" %d",i); } void pascal f(integer :i,integer:j,integer :k) { write(i,j,k); }

1 Answers  


source code for delete data in array for c

1 Answers   TCS,






write a c-program to find gcd using recursive functions

5 Answers   HTC, Infotech,


main() { extern int i; i=20; printf("%d",i); }

1 Answers   Value Labs,


main() { extern out; printf("%d", out); } int out=100;

1 Answers  


Write a Program that Inputs 10 Numbers in an Array and Show the Maximum Number

2 Answers   Ace Info,


write a c-program to display the time using FOR loop

3 Answers   HCL,


void main() { int i=10, j=2; int *ip= &i, *jp = &j; int k = *ip/*jp; printf(ā€œ%dā€,k); }

1 Answers  


What is the match merge ? compare data step match merge with proc sql merge - how many types are there ? data step vs proc sql

0 Answers  


Categories