The kids Ram and Anandh are using magic numbers. For example, Ram magic number is 4 and Anandh magic number is 6. The kids exchange their magic number and display the Ram magic number is 6 and Anandh magic number is 4. Implement the above logic using function. [Note: Use call by address]
#include <iostream>
using namespace std;
void exchangeNumbers(int *num1, int *num2)
{
int tmp = *num1;
*num1 = *num2;
*num2 = *num1;
}
int main()
{
int RamNumber = 4;
int AnandthNumber = 6;
cout << "Ram magic number is " << RamNumber << endl;
cout << "Anandth magic number is " << AnandthNumber << endl;
cout << endl << "Kids are excanging their numbers..." << endl << endl;
exchangeNumbers(&RamNumber, &AnandthNumber);
cout << "Now Ram magic number is " << RamNumber << endl;
cout << "Now Anandth magic number is " << AnandthNumber << endl;
}
Comments
Leave a comment