How to swap to numbers using a third variable called temp in C++ Program

CWC
1 Min Read

C++ program to swap to numbers using a third variable called temp.

 #include 
int main()
{
int a = 40;
int b = 20;
int temp;
cout << "Value of a (before swap): " << a << endl;
cout << "Value of b (before swap): " << b << endl;
temp=a;
a=b;
b=temp;
cout << "Value of a (after swap): " << a << endl;
cout << "Value of b (after swap): " << b << endl;
return 0;
} 
Share This Article
Leave a comment

Leave a Reply

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

English
Exit mobile version