Answer to Question #351000 in C++ for Noelle

Question #351000

Write a function called maximum() that accepts three integer

numbers as parameters. The maximum() that returns maximum value

of three arguments that are passed to the function when it is

called. Assume that all three arguments will be of the same data

type.


1
Expert's answer
2022-06-16T07:47:55-0400
#include <iostream>

template<typename num>

num maximum(num a, num b, num c) {
    if (a > b && a > c) {
        return a;
    } else if (b > c) {
        return b;
    } else {
        return c;
    }
}

int main()
{
    int a = 42;
    int b = 20;
    int c = 12;

    float d = 19.07;
    float e = 19.09;
    float f = 19.01;

    double j = 16.0475;
    double k = 16.0155;
    double l = 16.0622;

    std::cout << maximum(a, b, c) << "\n";
    std::cout << maximum(d, e, f) << "\n";
    std::cout << maximum(j, k, l) << std::endl;
    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