Answer to Question #341785 in C++ for LM.

Question #341785

(ii) Write a void function that receives four int parameters: the first two by value and the last two by reference. Name the formal parameters n1, n2, sum and diff. The function should calculate the sum of the two parameters passed by value and then store the result in the first variable passed by reference. It should calculate the difference between the two parameters passed by value and then store the result in the second parameter passed by reference. When calculating the difference, subtract the larger value from the smaller value. Name the function calcSumAndDiff.


1
Expert's answer
2022-05-18T08:33:13-0400
void calcSumAndDiff(int n1, int n2, int &sum, int &diff)
{
    sum = n1 + n2;
    
    if(n1 < n2)
        diff = n2 - n1;
    else
        diff = n1 - n2;
}

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