How to find the Minimum of Two Numbers in Rust - Step by Step Examples
How to find the Minimum of Two Numbers in Rust ?
Answer
To find the minimum of two numbers in Rust, you can use the std::cmp::min function.
✐ Examples
1 Minimum of Two Numbers
In this example,
- We declare two variables
a
andb
and assign values to them. - We use the
std::cmp::min
function to find the minimum ofa
andb
. - We print the minimum value.
Rust Program
// Minimum of Two Numbers
fn main() {
let a = 10;
let b = 15;
let min_val = std::cmp::min(a, b);
println!("Minimum of {} and {} is: {}", a, b, min_val);
}
Output
Minimum of 10 and 15 is: 10
Summary
In this tutorial, we learned How to find the Minimum of Two Numbers in Rust language with well detailed examples.