Answer to Question #184219 in C++ for Vijay Raj

Question #184219

Find Maximum of two integers, two float and two characters using function template


Runtime Input :

4.2

2.4

4.2


5

8

5

8


Z

A

Z

A


1
Expert's answer
2021-04-22T07:24:57-0400
#include <iostream>

template<class T>
T Max(T a, T b) {
    return a > b? a : b;
}

int main() {
    float fa, fb;
    int ia, ib;
    char ca, cb;

    std::cin >> fa >> fb;
    std::cout << Max(fa, fb) << '\n';

    std::cin >> ia >> ib;
    std::cout << Max(ia, ib) << '\n';

    std::cin >> ca >> cb;
    std::cout << Max(ca, cb) << '\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