add two numbers in rust

To add two numbers in Rust, you can create two variables of the same data type and use the + operator to add them together.

Here is an example code snippet:

main.rs
fn main() {
    let num1 = 5;
    let num2 = 10;

    let sum = num1 + num2;

    println!("The sum of {} and {} is: {}", num1, num2, sum);
}
142 chars
9 lines

In this example, we declare two variables num1 and num2 with values 5 and 10, respectively. Then we create a third variable sum which is the sum of num1 and num2. Finally, we print out the result using println! macro.

When you run this code, it should output:

main.rs
The sum of 5 and 10 is: 15
27 chars
2 lines

gistlibby LogSnag