How to find the Maximum of Three Numbers in C++ - Step by Step Examples
How to find the Maximum of Three Numbers in C++ ?
Answer
To find the maximum of three numbers in C++, you can use the `std::max` function from the
✐ Examples
1 Find Maximum of Three Numbers
In this example,
- We include the
header to use the `std::max` function. - We declare three variables
a
,b
, andc
with the numbers to compare. - We use the `std::max` function to compare the numbers and get the maximum.
C++ Program
#include <iostream>
#include <algorithm>
int main() {
int a = 5;
int b = 8;
int c = 3;
int max = std::max(std::max(a, b), c);
std::cout << "Maximum of three numbers is: " << max << std::endl;
return 0;
}
Output
Maximum of three numbers is: 8
Summary
In this tutorial, we learned How to find the Maximum of Three Numbers in C++ language with well detailed examples.