max and min function in c++
int a = min(2,3); // for two arguments
int b = max(2,3);
int x = min({2,3,4,5}); // for more than two arguments
int y = max({2,3,4,5});
// a = 2 b = 3
// x = 2 y = 5
max function in c++
// C++ program to demonstrate the use of std::max
// C++ program to demonstrate the use of std::max
#include
#include
using namespace std;
int main()
{
// Comparing ASCII values of a and b
cout << std::max('a','b') << "\n";
// Returns the first one if both the numbers
// are same
cout << std::max(7,7);
return 0;
}
c++ max of array
cout << " max element is: " << *max_element(array , array + n) << endl;
max c++
// max example
#include // std::cout
#include // std::max
int main () {
std::cout << "max(1,2)==" << std::max(1,2) << '\n';
std::cout << "max(2,1)==" << std::max(2,1) << '\n';
std::cout << "max('a','z')==" << std::max('a','z') << '\n';
std::cout << "max(3.14,2.73)==" << std::max(3.14,2.73) << '\n';
return 0;
}
|