0
0
Rustprogramming~20 mins

Arithmetic operators in Rust - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Rust Arithmetic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
What is the output of this Rust code using arithmetic operators?
Consider the following Rust code snippet. What will it print when run?
Rust
fn main() {
    let a = 10;
    let b = 3;
    let result = a % b + a / b * b;
    println!("{}", result);
}
A10
B3
C9
D1
Attempts:
2 left
๐Ÿ’ก Hint
Remember the order of operations: division and multiplication happen before addition.
โ“ Predict Output
intermediate
2:00remaining
What is the value of x after this Rust code runs?
Look at this Rust code. What is the final value of x?
Rust
fn main() {
    let mut x = 5;
    x += 3 * 2 - 4 / 2;
    println!("{}", x);
}
A8
B11
C9
D10
Attempts:
2 left
๐Ÿ’ก Hint
Calculate the expression on the right side first, then add to x.
โ“ Predict Output
advanced
2:00remaining
What does this Rust code print?
Analyze this Rust code snippet and determine its output.
Rust
fn main() {
    let a = 7;
    let b = 2;
    let c = a / b;
    let d = a as f64 / b as f64;
    println!("{} {}", c, d);
}
A3 3.5
B3 3
C3.5 3
D3.5 3.5
Attempts:
2 left
๐Ÿ’ก Hint
Integer division truncates, but casting to float allows decimal division.
โ“ Predict Output
advanced
2:00remaining
What is the output of this Rust code with mixed arithmetic?
What will this Rust program print?
Rust
fn main() {
    let x = 4;
    let y = 3;
    let z = (x + y) * (x - y) / y;
    println!("{}", z);
}
A7
B2
C1
D3
Attempts:
2 left
๐Ÿ’ก Hint
Calculate inside parentheses first, then multiply, then divide.
โ“ Predict Output
expert
2:00remaining
What is the output of this Rust code involving overflow with wrapping arithmetic?
Consider this Rust code using wrapping_add. What will it print?
Rust
fn main() {
    let max = u8::MAX; // 255
    let result = max.wrapping_add(10);
    println!("{}", result);
}
A0
B265
C10
D9
Attempts:
2 left
๐Ÿ’ก Hint
Wrapping addition wraps around on overflow instead of panicking.