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.rs142 chars9 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.rs27 chars2 lines
gistlibby LogSnag