To divide two numbers in Rust, you can use the /
operator as shown below:
main.rs120 chars7 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.rs25 chars2 lines
Here, the output is 5
because a / b
results in 10 / 2
which equals to 5
.
gistlibby LogSnag