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 do we swap or interchange any 2 numbers without using
Temporary variable...Anybody can pls answer it.. Thanks in
Advance

Answers were Sorted based on User's Feedback



How do we swap or interchange any 2 numbers without using Temporary variable...Anybody can pls ans..

Answer / manju

main()
{
int a=16,b=19;
a=a+b;
b=a-b;
a=a-b;
printf("a and b are:%d\t%d",a,b);
}

Output:
a and b are:19 16

Is This Answer Correct ?    16 Yes 3 No

How do we swap or interchange any 2 numbers without using Temporary variable...Anybody can pls ans..

Answer / surendra jhajhra

int x,y;

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

Is This Answer Correct ?    9 Yes 2 No

How do we swap or interchange any 2 numbers without using Temporary variable...Anybody can pls ans..

Answer / raghuram.a

int x,y;

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

or

int x,y;

x=x^y;
y=x^y;
x=x^y;

Is This Answer Correct ?    11 Yes 7 No

How do we swap or interchange any 2 numbers without using Temporary variable...Anybody can pls ans..

Answer / srikanth

int x,y;

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

or

int x,y;

x=x^y;
y=x^y;
x=x^y;

or

int x,y;
x*=xy;
y=x/y;
x=x/y;

Is This Answer Correct ?    4 Yes 1 No

How do we swap or interchange any 2 numbers without using Temporary variable...Anybody can pls ans..

Answer / emperor of america

using bitwise operator works 100%:
x^=y;
y^=x;
x^=y;

using +/- works sometime, need to consider overflow.

Is This Answer Correct ?    4 Yes 2 No

How do we swap or interchange any 2 numbers without using Temporary variable...Anybody can pls ans..

Answer / divya

#include<stdio.h>
main()
(
clrscr();
int a,b;
printf("enter a and b values");
scanf("%d \n %d",&a,&b);
printf("before swaping a value is:%d",a);
printf("before swaping b value is:%d",b);
a=a+b;
b=a-b;
a=a-b;
printf("after swaping a value is:%d",a);
printf("after swaping b value is:%d",b);
getch();
}

Is This Answer Correct ?    1 Yes 0 No

How do we swap or interchange any 2 numbers without using Temporary variable...Anybody can pls ans..

Answer / girish

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int a,b;
clrscr();
printf("Enter the two values:");
scanf("%d%d",&a,&b);
swap(a,b);
pritnf("the swaping of given two values are:\na=%d,b=%
d",a,b);
getch();
}

Is This Answer Correct ?    0 Yes 3 No

How do we swap or interchange any 2 numbers without using Temporary variable...Anybody can pls ans..

Answer / mangala pandi

Logically it is not possible. so your question is worng.

Is This Answer Correct ?    1 Yes 15 No

Post New Answer

More C Interview Questions

What is diffrance between declaration and defination of a variable or function

4 Answers  


what is the advantage of function pointer

16 Answers   CMC, CS, Freshdesk, L&T, LG Soft, Matrix, TCS,


What is use of null pointer in c?

0 Answers  


all c language question

0 Answers   Wipro,


Is javascript based on c?

0 Answers  


What is advantage of pointer in c?

0 Answers  


in a town the percentage of men is 52 the percentage of total literacy is 48 if total percentage of literate men is 35 of the total population write a program to find the total no of the literate men and women if the population of the town is 80000

3 Answers  


What are the application of void data type in c?

0 Answers  


int a=1,b=2,c=3; printf("%d,%d",a,b,c); What is the output?

14 Answers   Verifone,


Identify the correct argument for the function call fflush () in ANSI C: A)stdout B)stdin C)stderr D)All the above

5 Answers   Accenture, TCS,


du u know test pattern for robosoft? Plz share

1 Answers   RoboSoft, TATA, Wipro,


void main() { int i=5; printf("%d",i+++++i); }

17 Answers   ME,


Categories