- +
- -
- *
- /
- %
Numerical operations on integers
- The division keeps the type so dividing one integer by another integer will always return an integer.
examples/numbers/calc/src/main.rs
fn main() { let x = 23; let y = 19; println!("{x}"); println!("{y}"); let add = x + y; println!("add: {add}"); let multiple = x * y; println!("multiple: {multiple}"); let neg = -x; println!("neg: {neg}"); let diff = y - x; println!("diff: {diff}"); let div = x / y; println!("div: {div}"); let modulus = x % y; println!("mod: {modulus}"); }
23 19 add: 42 multiple: 437 neg: -23 diff: -4 div: 1 mod: 4