Control flow is a fundamental concept in any programming language, including Rust. The if-else statement is a basic control flow construct that allows you to execute different code blocks based on certain conditions.
Your task
In this challenge, you will write a function is_even(n: i32) -> bool that checks if a given number is even or odd using an if-else statement. The function should return true if the number is even, and false if it is odd.
Requirements
- The function should take an integer as input.
- Use an
if-elsestatement to determine if the number is even. - Return
trueif the number is even. - Return
falseif the number is odd.
Example
assert_eq!(is_even(4), true);assert_eq!(is_even(7), false);assert_eq!(is_even(0), true);assert_eq!(is_even(-2), true);assert_eq!(is_even(-3), false);
pub fn is_even(n: i32) -> bool {// Your code here...}