Untitled

 avatar
unknown
plain_text
10 months ago
655 B
4
Indexable
#include <iostream>

// Define the template
template <typename T>
T Max(T a, T b) {
    return (a > b) ? a : b;
}

int main() {
    // Test with integers
    int int1 = 10, int2 = 20;
    std::cout << "Max of " << int1 << " and " << int2 << " is " << Max(int1, int2) << std::endl;

    // Test with floating-point numbers
    double double1 = 10.5, double2 = 7.3;
    std::cout << "Max of " << double1 << " and " << double2 << " is " << Max(double1, double2) << std::endl;

    // Test with characters
    char char1 = 'a', char2 = 'z';
    std::cout << "Max of " << char1 << " and " << char2 << " is " << Max(char1, char2) << std::endl;

    return 0;
}
Editor is loading...
Leave a Comment