Example 1: Swap Numbers in c++
#include <iostream>Output
using namespace std;
int main()
{
int a = 5, b = 10, temp;
cout << "Before swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
temp = a;
a = b;
b = temp;
cout << "\nAfter swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
return 0;
}
Before swapping.
a = 5, b = 10
After swapping.
a = 10, b = 5
No comments:
Post a Comment