Program to Swap two numbers

#include "iostream"
using namespace std;
void main() {
int   var1 = 10, var2 = 20, temporary;
cout << "Before swapping." << endl;
cout << "var1 = " << var1 << ", var2 = " << var2 << endl;
temporary = var1;
var1 = var2;
var2 = temporary;
cout << "\nAfter swapping." << endl;
cout << "var1 = " << var1 << ", var2 = " << var2 << endl;
}
Output
Before swapping
var1 = 10, var2 = 20
After swapping
var1 = 20, var2 = 10

Post a Comment

0 Comments