Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Max of Two

Create a function called max that takes two i32 values and returns the larger one. Test it with a few different pairs of numbers.

Expected output:

text
Max of 3 and 7 is 7
Max of 10 and 2 is 10
Max of 5 and 5 is 5

Hints:

  • Define with fn max(a: i32, b: i32) -> i32
  • Use an if expression to compare a and b
  • Remember, if can be used as an expression in Rust: if a >= b { a } else { b }
rust
fn main() {
}