Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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 / priyam

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

Is This Answer Correct ?    1 Yes 8 No

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

Answer / vinay kumar shukla

i am not giving answer
all above answer for swaping integer type variables without
third
i want answer in string type

Is This Answer Correct ?    6 Yes 15 No

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

Answer / saumya

Thanks a lot guys. It is giving very good analysis.

Is This Answer Correct ?    7 Yes 19 No

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

Answer / koneru gowtham

plz check 3 aswer is perfect, 2 one mat be wrong in some cases

Is This Answer Correct ?    47 Yes 63 No

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

Answer / kumar

Using Assembly language( Using Accumulator)...Without using
any arithmatic...without using any Pointer...without
declaring third varible

int a = 20;
int b = 10;
__asm
{
mov EAX,b
push EAX
mov EAX,a
mov b,EAX
pop EAX
mov a,EAX
}

Is This Answer Correct ?    17 Yes 33 No

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

Answer / meenama

The first two answers are correct. Third will FAIL in the
case the second num is 0. The #19 one still uses a third
variable.

Is This Answer Correct ?    5 Yes 21 No

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

Answer / mangesh

#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
clrscr();
printf("\nEnter two numbers:");
scanf("%d%d",&a,&b);
printf("\nThe numbers after swapping are %d %d",b,a);
getch();
return 0;
}

Is This Answer Correct ?    0 Yes 18 No

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

Answer / rehan

#include<stdio.h>
main()
{
int a,b;
printf("Enter any two numbers\n");
scanf("%d%d",&a,&b);
printf("The values before swapping are\n%d %d\n",a,b);
swap(&a,&b);
printf("The values after swapping are\n%d %d\n",a,b);
getch();
}

swap(*x,*y)
{
int t;
t=*x;
*x=*y;
*y=t;
}

Is This Answer Correct ?    5 Yes 24 No

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

Answer / divakar

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

Is This Answer Correct ?    25 Yes 57 No

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

Answer / javaskills

x = y | (y=x);

Is This Answer Correct ?    11 Yes 54 No

Post New Answer

More C Code Interview Questions

how to print 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 using any loop(for or while) only once(only 1 loop) and maximum 2 variables using C.

19 Answers   Cap Gemini, Infosys,


Print an integer using only putchar. Try doing it without using extra storage.

2 Answers  


#include<stdio.h> main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); break; case j: printf("BAD"); break; } }

1 Answers  


PROG. TO PRODUCE 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1

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  


main( ) { int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) { printf(ā€œ%dā€ ,*a); a++; } p = a; for(j=0; j<5; j++) { printf(ā€œ%d ā€ ,*p); p++; } }

1 Answers  


to remove the repeated cahracter from the given caracter array. i.e.., if the input is SSAD output should of SAD

6 Answers   Synergy,


Is the following statement a declaration/definition. Find what does it mean? int (*x)[10];

1 Answers  


Write a program to receive an integer and find its octal equivalent?

7 Answers  


Write a program to implement the motion of a bouncing ball using a downward gravitational force and a ground-plane friction force. Initially the ball is to be projected in to space with a given velocity vector

2 Answers  


main() { float f=5,g=10; enum{i=10,j=20,k=50}; printf("%d\n",++k); printf("%f\n",f<<2); printf("%lf\n",f%g); printf("%lf\n",fmod(f,g)); }

1 Answers  


main() { register int a=2; printf("Address of a = %d",&a); printf("Value of a = %d",a); }

3 Answers  


Categories