Complete the code to calculate the remainder of division.
let remainder = a [1] b;The % operator gives the remainder after division.
Complete the code to check if a number is even.
if num [1] 2 == 0 { println!("Even"); }
The remainder operator % with 2 checks if a number is even (remainder 0) or odd.
Fix the error in the code to compute the greatest common divisor (GCD) using Euclid's algorithm.
fn gcd(mut a: i32, mut b: i32) -> i32 {
while b != 0 {
let temp = b;
b = a [1] b;
a = temp;
}
a
}Euclid's algorithm uses the remainder operator % to update b.
Fill both blanks to create a map of numbers to their squares for numbers greater than 3.
let squares: std::collections::HashMap<_, _> = (1..10) .filter(|&x| x [1] 3) .map(|x| (x, x [2] x)) .collect();
Filter numbers greater than 3 using > and square numbers using multiplication *.
Fill all three blanks to create a dictionary of uppercase letters mapped to their ASCII codes if code is greater than 65.
let letters: std::collections::HashMap<_, _> = ('a'..='z') .map(|c| (c[1], c[3] as u8)) .filter(|&(_, code)| code [2] 65) .collect(); println!("{:?}", letters);
Convert character to uppercase with .to_ascii_uppercase(), filter codes greater than 65 with >.
