The source code to demonstrate the match statement without returning the value is given below. The given program is compiled and executed successfully.
// Rust program to demonstrate the
// match statement without returning value
fn main() {
let mut weekNum:i32 = 2;
match weekNum {
1=> println!("Sunday"),
2=> println!("Monday"),
3=> println!("Tuesday"),
4=> println!("Wednesday"),
5=> println!("Thursday"),
6=> println!("Friday"),
7=> println!("Saturday"),
_=> println!("Invalid week number")
};
}
Output:
Monday
Explanation:
Here, we created an integer variable weekNum with an initial value of 2. Then we found the weekday from week number using the match statement without returning value and printed the result.
Program/Source Code:
The source code to demonstrate the match statement without returning the value is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we created an integer variable weekNum with an initial value of 2. Then we found the weekday from week number using the match statement without returning value and printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer