Swap Two Numbers using C++ Program

In this program, I will explain how to swap two numbers using c++ program with the help of temporary variable. in this program, we are using the three variables a, b and temp.

Swap Two Numbers using C++ Program

Before swapping.
a = 5, b = 10
****************
After swapping.
a = 10, b = 5

Below is the anothe example of number swapping without using any third variable.

Before swapping.
a = 5, b = 10
****************
After swapping.
a = 10, b = 5

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:


Prem Tiwari

An engineer by profession and a passionate blogger by heart. Founder of FreeWebMentor.com (A Programming blog for beginners), Tech Speaker at various forums. A part from this he is an open source enthusiast, WordPress Lover, Blogger, SEO, and Growth Strategic.

Article Tags: , , ,