find the area of a trapezoid in rust

To find the area of a trapezoid in Rust, we need to use the formula:

main.rs
Area = ((base1 + base2) * height) / 2
38 chars
2 lines

where base1 and base2 are the lengths of the parallel sides of the trapezoid, and height is the perpendicular distance between the bases.

Here's the Rust code to calculate the area of a trapezoid:

main.rs
fn main() {
    let base1 = 10.0;
    let base2 = 15.0;
    let height = 8.0;
    let area = ((base1 + base2) * height) / 2.0;
    println!("The area of the trapezoid is: {}", area);
}
185 chars
8 lines

In this code, we have initialized the values of base1, base2, and height using floating-point numbers. We have then calculated the area of the trapezoid using these values and the formula mentioned above.

Finally, we have printed the value of area using the println! macro.

gistlibby LogSnag