Max and Min
Max
Function
Returns the largest of a and b. If both are equivalent, a is returned.
Declaration
max(variable or value 1,variable or value 2);
Example
#include <iostream>
#include <algorithm> //for max
using namespace std;
int main () {
cout << max(1,2) << endl;
cout << max('s','m') << endl;
cout << max(1.23,2.34) << endl;
return 0;
}
Output:
2
s
2.34
Min
Function
Returns the smallest of a and b. If both are equivalent, a is returned.
Declaration
min(variable or value 1,variable or value 2);
Example
#include <iostream>
#include <algorithm> //for min
using namespace std;
int main () {
cout << min(1,2) << endl;
cout << min('s','m') << endl;
cout << min(1.23,2.34) << endl;
return 0;
}
Output:
1
m
1.23