-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;

Sunday, 9 August 2015

Swapping two numbers

"Swapping two number" is one of the most popular and easiest program of C++. If you want to make a good logic in C++,then you should practice this code.

Today I am here with the source code of this program.Hope you will like my effort.

Source code

sSwapping in C++

Output

Output of swapping

Logic

Below is the logic of this program.

I have taken 3 variables for this program,"a,b and tem(or temporary).

According to logic,

Suppose the value of a is 10 and the value of b is 20.

According to the given condition,

tem=a;
tem=10;
a=b
10=b or b=10;
b=tem
20=tem
b=10.

So,after swapping,the value of "a" becomes 20 and the value of "b" becomes 10. 

No comments:

Post a Comment