find the area of a rhombus in rust

To find the area of a rhombus, we need to know the length of its diagonals. Here's a Rust function that takes in the lengths of the diagonals and returns the area of the rhombus:

main.rs
fn rhombus_area(diagonal1: f64, diagonal2: f64) -> f64 {
    (diagonal1 * diagonal2) / 2.0
}
93 chars
4 lines

We can use this function as follows:

main.rs
fn main() {
    let diagonal1 = 10.0;
    let diagonal2 = 6.0;
    let area = rhombus_area(diagonal1, diagonal2);
    println!("The area of the rhombus is {}", area);
}
169 chars
7 lines

This will output:

main.rs
The area of the rhombus is 30
30 chars
2 lines

Note that the length of the diagonals should be in the same units (e.g. both in centimeters) for this formula to work.

gistlibby LogSnag