How to swap values between two variables without using a
third variable?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
what is fisrt female program
Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fit" instead of the number and for the multiples of five print "Bit". For numbers which are multiples of both three and five print "FitBit".
how many languages .net is supporting now?
Info for guidewire documents and interview questions
What is test execution and when will we start execution please send me one example for this question
why we use static with only main()class not with other class
cobol is execution r not without jcl
Create a class TicTacToe that will enable you to write a complete program to play the game of Tic-Tac-Toe. The class contains as private data a 3- by-3 double array of integers. The constructor should initialize the empty board to all zeros. Allow two human players. Wherever the first player moves, place a 1 in the specified square; place a 2 wherever the second player moves. Each move must be to an empty square. After each move determine whether the game has been won and whether the game is a draw. If you feel ambitious, modify your program so that the computer makes the moves for one of the players automatically. Also, allow the player to specify whether he or she wants to go first or second. If you feel exceptionally ambitious, develop a program that will play three-dimensional Tic-Tac-Toe on a 4-by-4-by-4
what is the BAM? where we can use it in BizTalk server?
Fortran cannot have value by reference True or False?
what are resources in case of Threads
What's the difference b/w Table & Templete in Smartform?