Answer to Question #172800 in C++ for Ananya

Question #172800

Write an inline function sum() with four parameters that calculates the

arguments

provided and returns their sum.

Parameters: Four variables of type long.

Returns: The sum of type long.

Use the default argument 0 to declare the last two parameter.


1
Expert's answer
2021-03-18T03:30:16-0400
#include <iostream> 
using namespace std; 
inline long sum(long a, long b, long c = 0, long d = 0) 
{ 
    return a+b+c+d; 
} 
int main() 
{ 
    cout << "The sum of (1,2) is: " << sum(1,2) << "\n"; 
    cout << "The sum of (1,2,3) is: " << sum(1,2,3) << "\n"; 
    cout << "The sum of (1,2,3,4) is: " << sum(1,2,3,4) << "\n"; 
    return 0; 
} //

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