find the area of a parallelogram in rust

We can find the area of a parallelogram by multiplying the base of the parallelogram by its height. Here's how we can do it in Rust:

main.rs
fn parallelogram_area(base: f64, height: f64) -> f64 {
   base * height
}

fn main() {
   let base = 10.0;
   let height = 5.0;
   let area = parallelogram_area(base, height);

   println!("The area of the parallelogram is: {}", area);
}
238 chars
12 lines

In this code, we create a function named parallelogram_area that takes base and height as arguments and returns the area of the parallelogram.

We then call the parallelogram_area function in the main function and pass in values for the base and height variables. Finally, we print the area of the parallelogram to the console.

Note that we are using f64 for our data types to handle floating-point calculations.

gistlibby LogSnag