Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Min of Three

Write a generic function min_of_three that takes three values of the same type and returns the smallest. Use it with integers.

Expected output:

text
Smallest: 5

Hints:

  • fn min_of_three<T: PartialOrd>(a: T, b: T, c: T) -> T
  • Compare pairs: if a is smallest return a, else compare b and c
  • You can nest if/else: if a <= b && a <= c { a } else if b <= c { b } else { c }
rust
fn main() {
}