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

my answer is very correct compared to the others.(1 to 3)

in answer 1 pinky declared a variable(ia) that is never
used in the program and used a variable(a) that is not
declared.finally pinky did not close main function i.e }

in answer 2 Banti Sharma has written the logic of the
program like a program, but he did not wrote the actual
program,if it is a program then the output is nothing,
because there is no statement present for displaying the
values of a and b


in answer 3 Mona also written the logic of the program like
Banti Sharma but Mona wrote it in a method.and mona never
called that method and from where mona is passing values to
var1 and var2.and mona did not displayed the result.

but in answer 4, that means in my answer,

i did not write the entire program,i just explained the
logic how u can swap without the third variable.

i have taken two variables and assigned sample values
(x=10,y=20) to them and explained each and every line with
that sample values, such that the person who asked this
question can write a program of his own.

Banti Sharma, i think u are not trying to answer the
questions but u are trying to point out the silly mistakes
in answers posted by others.

Is This Answer Correct ?    10 Yes 11 No

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

Answer / sushma rani

Here we have two variable A=4, B=3

we need to swap values without taking any third variable
result should be A=3, B=4

for that we can do ,
A=A+B-A (e.g. A=4+3-4 => 3)
and
B=B+A-B (e.g. B=3+4-3 => 4)

That's it....

Thanks & Regards
Sushma Rani
Bangalore
===========

Is This Answer Correct ?    3 Yes 7 No

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

Answer / banti sharma

Miss Sobha upto My Knowlegde the answer of "Shiv" was most
appropriate and if you have Any knowledge of Programming I
repeat again "Any knowledge of programming" then you may
find it out yourself that Bitwise Shift Operation is much
more time Efficient then that of "+","-","*","/.And if I say
about my answer then it is also correct having No mistakes
as the Question is "How to swap values between two variables
without using a third variable?" so if you read it carefully
then it does not say anywhere to print the Swaped values.I
think you have got Y i wrote like that,IF I say about
another logic then one more logic may be used like:

a=a*b;
b=a/b;
a=a/b;

though I m using Multiply and Devision still its better then
my past logic(so better then urs aytomatically) now if You
may find y? multiplication/Devision is more efficient then
Plus/minus then Do Googling.
have a good day

Is This Answer Correct ?    7 Yes 12 No

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

Answer / kiran

int a=10,b=20;
a=b;
b=a/2;

Is This Answer Correct ?    3 Yes 49 No

Post New Answer

More Programming Languages AllOther Interview Questions

Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except for 1 number. Find the missing number

0 Answers   Amazon,


Write a program to show polymorphism.

0 Answers   Genpact,


What are the other ways to create an object with out calling new keyword in java?

2 Answers   HCL,


19. Given a system that is described with the following equation, X=A+(B.(A̅+C)+C)+A.B.(D̅+E̅) a) Simplify the equation using Boolean Algebra. b) Implement the original and then the simplified equation with a digital circuit. c) Implement the original and then the simplified equation in ladder logic.

0 Answers   Bajak Paint,


how to swap all the values without using temporary variable. tha values r a = 20, x=60 and p=2.

5 Answers   DST Global Solutions, iGate,


Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except for 2 numbers. Find the missing numbers.

0 Answers   Amazon,


along with oracle which language will be beneficial to have knowledge with,java,.net,since i m doing oracle have appeared for 8th sem BEIT,plz suggest

0 Answers  


what is mutex?

4 Answers   Axiom, Blue Star, SQL Star,


what is the difference between SCAN AND CHECK,LOKUP AND XFOOT? where we can use thease opcodes? Can any body tell me real time senariao with example?

0 Answers  


HTML is a subset of

8 Answers  


two MIT math grads bump into each other at Fairway on the upper west side. they haven't seen each other in over 20 years. the first grad says to the second: "how have you been?" second: "great! i got married and i have three daughters now" first: "really? how old are they?" second: "well, the product of their ages is 72, and the sum of their ages is the same as the number on that building over there.." first: "right, ok.. oh wait.. hmm, i still don't know" second: "oh sorry, the oldest one just started to play the piano" first: "wonderful! my oldest is the same age!" problem: how old are the daughters?

2 Answers  


What is a singleton linked list?

1 Answers   Wipro,


Categories