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 values between two variables without using a
third variable?

Answers were Sorted based on User's Feedback



How to swap values between two variables without using a third variable?..

Answer / srinivas

int a=2,b=3;
a=a+b-(b=a); /*now a=3, b=2*/

Is This Answer Correct ?    2 Yes 0 No

How to swap values between two variables without using a third variable?..

Answer / chitra

main()
{
int a,b;

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

chitra write answer

Is This Answer Correct ?    1 Yes 0 No

How to swap values between two variables without using a third variable?..

Answer / kumar

//language using C#

int a=10;
int b=20;

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

thanks
Kumar
http://www.sourcecodehub.com/php/how-to-swap-values-of-two-variables-without-using-a-third-variable-integer/

Is This Answer Correct ?    1 Yes 0 No

How to swap values between two variables without using a third variable?..

Answer / joel pinto

a^=b^=a^=b;

Is This Answer Correct ?    2 Yes 2 No

How to swap values between two variables without using a third variable?..

Answer / nisay mizrahi

double a,b;
System.out.println("put in 2 numbers");
a=in.nextDouble();
b=in.nextDouble();
if(a>b){
a=a-b;
b=b+a;
a=b-a;

}
else
if(b>a){
b=b-a;
a=a+b;
b=a-b;
}
System.out.println("a is "+a);
System.out.println("b is "+b);
}

}

Is This Answer Correct ?    2 Yes 2 No

How to swap values between two variables without using a third variable?..

Answer / neha

class SwapBitwise
{
public void SwapByBitwise(int x, int y)
{
x =x ^ y;
y = x ^ y;
x = x ^ y;
System.out.println("x : " + x + " " + "y :" + y);
}
}
public class SwapOperation
{
public static void main(String[] args) {
SwapBitwise obj = new SwapBitwise();
obj.SwapByBitwise(200, 300);
}

}

Is This Answer Correct ?    1 Yes 1 No

How to swap values between two variables without using a third variable?..

Answer / adil

string a = "adil ahmad", b = "anuj gupta";
a = a + b;
b = a.Substring(0, a.Length - b.Length);
a = a.Substring(b.Length, a.Length - b.Length)

Is This Answer Correct ?    0 Yes 0 No

How to swap values between two variables without using a third variable?..

Answer / padma

Need more information related to,
1. the values and type of variables before doing a swap, in
order to do the efficient memory management and code
robustness.
2.the reason to swap without using third variable.

3.code efficiency increased due to the two variable alone.

4.pre and post conditions for swap

5.the programming laguage to be used to do swap.

Is This Answer Correct ?    0 Yes 0 No

How to swap values between two variables without using a third variable?..

Answer / guest

using swap instruction in micro controller.

Is This Answer Correct ?    0 Yes 0 No

How to swap values between two variables without using a third variable?..

Answer / guest

using swap instruction in micro controller.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Programming Languages AllOther Interview Questions

Have you used callsymputx? what points need to be kept in mind when using it?

0 Answers   GE,


Which language they use during interview?

0 Answers   State Bank Of India SBI,


6.int x=10; float y=20; a=x%2=? b=y%2=?

1 Answers  


what is difference between java and c#

2 Answers   Cyient,


What is algorithm in SCD Type2(SAS DI Studio Transformaton)?

2 Answers  


Difference between views and index in sas programming

0 Answers   Ventois,


What parameters are used to run a JCL JOB on a perticular DAY and TIME and DATE

1 Answers  


what is the difference between an OS(operating system) and Framework?

0 Answers  


What is BASIS

0 Answers  


< DL Compact > tag is used for

0 Answers  


Write a shell program where you enter a number which corresponds to K.M. Find out the corresponding values in m, cm, inches, and feet. Hints:- 1 k.m= 1000 m 1 m= 100 cm 1 inches= 2.54 cm. 1 feet= 12 inches

0 Answers  


Question:Why is mapping required? Computer 'Paging' & 'Segmentation'. Question:Give the disadvantages of Havander's Strategies. Question: What do you mean by Belady's Anomaly. - Describe with example. Question: Discuss the various function of OS. Question: Give a brief discussion on schedulers & Dispatchers with respect to process management.

0 Answers  


Categories