Answer to Question #182439 in C++ for P. Gokul

Question #182439

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]


1
Expert's answer
2021-04-21T18:18:37-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS