In this post, we are going to write a c++ program to swap the two numbers by using the third variable. you can debug and run this code in CodingBlocks compile.
C++ program to swap two numbers using a third variable.
#include<iostream> #include<conio.h> int main(void) { int a,b,c; a=10; b=20; c=a; a=b; b=c; std::cout<<"The value of a is = "<<a<<std::endl; std::cout<<"The value of b is = "<<b; getch(); return 0; }
Output
The value of a is = 20 The value of b is = 10