subtract two numbers in rust

Subtracting two numbers in Rust is simple and can be achieved using the - operator. Here's an example:

main.rs
fn main() {
    let num1 = 10;
    let num2 = 5;
    let result = num1 - num2;
    println!("Result: {}", result);
}
117 chars
7 lines

In this example, we declare two integer variables num1 and num2, both initialized with values 10 and 5 respectively. We subtract num2 from num1 and store the result in a variable named result. Finally, we print the value of result which is 5.

The output of the program will be:

main.rs
Result: 5
10 chars
2 lines

Note that both num1 and num2 are of type i32 (32-bit signed integer) in this example. The resulting value of the subtraction operation will also be of type i32.

gistlibby LogSnag