Computer Science, asked by jithakral93, 1 year ago

Write a logic to exchanged the value of two variable. a=10,b=20

Answers

Answered by nitish8089
2
 1. \: create \: the \: temproray \: variable \\ (say \: temp)...\\ 2. \: assign \: the \: value \: of \: a \: in \: temp - \\ rorary \: variable(temp = a) \\ 3. \: a \: assign \: the \: value \: of \: b(a = b) \\ 4.finally \: b \: assign \: the \: value \: of \\ (b = temp).. \\ and \: finally \: value \: exchange

nitish8089: correction..
jithakral93: means
nitish8089: actually mistype in line 4 initally b=a.. but it's not true so i change b=temp.. and it's corrected
jithakral93: OK thank you
jithakral93: it's okay
Answered by Anonymous
2

Hi,

To exchange value of two cariables you have to make another varibale.

a = 10

b = 20

c = a // now c contains value of a which is 10

a = b // here a contains value of b which is 20

b = c // and here we are assining value of c which is 10 to variable b

so now a is equals to 20 and b is equals to 10

Similar questions