X=10,Y=20 you need to swap the numbers without using a
third variable?

Answers were Sorted based on User's Feedback



X=10,Y=20 you need to swap the numbers without using a third variable?..

Answer / bhaskar

X=X+y
Y=X-Y
X=X-Y

Is This Answer Correct ?    27 Yes 6 No

X=10,Y=20 you need to swap the numbers without using a third variable?..

Answer / venki

x=10 and y=20
x=x+y
=>x=10+20=30
=>x=30
y=x-y
=>y=30-20=10
=>y=10 ----->@1
x=x-y
=>x=30-10=20
=>x=20 ----->@2
now x and y values has been swaped
see @1 and @2

Is This Answer Correct ?    13 Yes 0 No

X=10,Y=20 you need to swap the numbers without using a third variable?..

Answer / test

Dim a,b
a=10
b=20
a = a + b
b = a - b
a = a - b
Msgbox a
msgbox b

Is This Answer Correct ?    9 Yes 0 No

X=10,Y=20 you need to swap the numbers without using a third variable?..

Answer / sandip patil

If X=10 & Y=20
then for swapping just go with following

Y=Y-X i.e. Y=20-10=10 here value of Y=10
X=X+Y i.e. X=10+10=20 Here value of X=20

It is swap

Is This Answer Correct ?    4 Yes 3 No

X=10,Y=20 you need to swap the numbers without using a third variable?..

Answer / ramyashetty

'a and b are two variables ; Following code swaps both number and string inputs

a = Inputbox("Enter a")
b = Inputbox("Enter b")


a = a + b

b = left(a,(instr(a,b)-1))
a = Right(a,(len(a)-len(b)))

msgbox "b ="&b
msgbox "a = "&a

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More QTP Interview Questions

how to post xml data from QTP scripts to any application?

0 Answers  


why qtp supports vbscript? and not for others just like cgi,phython,shell,perl,html and all..

4 Answers   Cap Gemini,


What is keyword driven framework, what is "key" in It.

2 Answers   IBM,


Can we add the function library directly from scripting in qtp instead of adding from resource tab?

5 Answers   IBM,


Explain the check points in QTP?

2 Answers  






what is keyword driven framework in qtp.

13 Answers   Cognizant, TCS,


How do you do batch testing in QTP, if so explain?

2 Answers  


While writing script using For Next Statement in QTP, I try defining the variable in Lib File I am getting syntax error whereas if I use the variable in script file, the script works fine. Can anyone help me in finding the reason behind this?. E:g Dim intStartRow (Define in Lib File----- say abc.vbs) Dim intRow (If I define this variable in Lib file I am getting Syntax error where as if I define in the script file ---- say xyz.mts the script works fine) IntStartRow=2 For intRow = intStartRow to xlWrksht.UsedRange.Rows.Count ‘Some Code here Next

1 Answers  


Difference between copy to action and call to action?

0 Answers  


Does QTP run in any environment?

0 Answers  


Tell me about qtp?

0 Answers  


What is the difference between keyword driven frameworkd and Modularisation framework?(Chandana)

5 Answers   Wipro,


Categories