divide two numbers in rust

To divide two numbers in Rust, you can use the / operator as shown below:

main.rs
fn main() {
    let a = 10;
    let b = 2;
    let result = a / b;
    println!("Result of division is: {}", result);
}
120 chars
7 lines

In this example, we first declare two variables a and b, and assign them values of 10 and 2, respectively. We then use the / operator to divide a by b, and store the result in the result variable. Finally, we print the result using println! macro.

The output of the above code would be:

main.rs
Result of division is: 5
25 chars
2 lines

Here, the output is 5 because a / b results in 10 / 2 which equals to 5.

gistlibby LogSnag