rust BMI

Certainly! Here's an example of calculating BMI in Rust:

fn calculate_bmi(weight: f32, height: f32) -> f32 {
    let height_m = height / 100.0;
    weight / (height_m * height_m)
}

fn main() {
    let weight = 70.0;
    let height = 170.0;
    let bmi = calculate_bmi(weight, height);
    println!("BMI: {:.2}", bmi);
}

In this example, we define a function called calculate_bmi that takes the weight (in kilograms) and height (in centimeters) as parameters. The function calculates the BMI by dividing the weight by the square of the height in meters.

In the main function, we initialize the weight and height variables with example values and call the calculate_bmi function to get the BMI. Finally, we print the BMI value with two decimal places using the println! macro.

To use this code, you'll need to have Rust installed on your system. You can compile and run the code using the cargo run command.