top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

how to swap values of two variables in c?

+2 votes
353 views

how many types we can swap values of two variables without using third variable?

posted Mar 23, 2015 by Devendra Bohre

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Just going the logic -
Assume you have two variable a and b and you want to swap the value of a and b then try the following logic -

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

Dry run assume a=5 and b =10
a=a+b means a=15 b=10
b=a-b means a=15 b=5
a=a-b means a=10 b=5

answer Mar 23, 2015 by Salil Agrawal
Similar Questions
+2 votes

How can I wwap value two variables without using third variable or +/- operator?

0 votes

a and b are compared against
the threshold ‘TH’, and the nearest value is voted as output

...