Swap Two Numbers using C++ Program

Prem Tiwari - - C++ Tutorial


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


Prem Tiwari

Prem Tiwari is the founder of FreeWebMentor.com and also a professional developer and a blogger by hobby.

Tags: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.