How to find the Maximum of Three Numbers in Rust - Step by Step Examples
How to find the Maximum of Three Numbers in Rust ?
Answer
To find the maximum of three numbers in Rust, you can use the `std::cmp::max` function.
✐ Examples
1 Find Maximum of Three Numbers
In this example,
- We import the std::cmp module to use the `max` function.
- We declare three variables
a
,b
, andc
with the numbers to compare. - We use the `max` function to compare the numbers and get the maximum.
Rust Program
fn main() {
let a = 5;
let b = 8;
let c = 3;
let max = std::cmp::max(std::cmp::max(a, b), c);
println!("Maximum of three numbers is: {}", max);
}
Output
Maximum of three numbers is: 8
Summary
In this tutorial, we learned How to find the Maximum of Three Numbers in Rust language with well detailed examples.