Posts

Showing posts with the label Arithmetic Operations

Arithmetic Operations

In Rust programming, arithmetic operations play a fundamental role in manipulating data. Rust provides a standard set of arithmetic operators, including addition, subtraction, multiplication, division, and the modulo operator, allowing for versatile computation capabilities. Let's explore these arithmetic operations in Rust with examples: 1. Addition ( + ): let a = 10; let b = 3; let c = a + b; // c = 13 2. Subtraction ( - ): let a = 10; let b = 3; let c = a - b; // c = 7 3. Multiplication ( * ): let a = 10; let b = 3; let c = a * b; // c = 30 4. Division ( / ): let a = 10; let b = 3; let c = a / b; // c = 3 (truncates the fractional part) 5. Modulo ( % ): let a = 10; let b = 3; let c = a % b; // c = 1 (remainder of 10 divided by 3) When performing division operations with floating-point values, the result retains decimal precision: let a = 10.0; let b = 3.0; let c = a / b; // c = 3.3333... Mixing different data types in arithmetic operations requires expli...