The source code to extract the last two digits from a given year is given below. The given program is compiled and executed successfully.
// Rust program to extract the
// last two digits from a given year
use std::io;
fn main()
{
let mut year:i32 =0;
let mut res:i32 =0;
let mut input = String::new();
println!("Enter year: ");
io::stdin().read_line(&mut input).expect("Not a valid string");
year = input.trim().parse().expect("Not a valid number");
res = year % 100;
println!("Result is: {}", res);
}
Output:
Enter year:
2021
Result is: 21
Explanation:
Here, we read the year from the user. After that, we extracted the last two digits from the given year and printed the result.
Program/Source Code:
The source code to extract the last two digits from a given year is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we read the year from the user. After that, we extracted the last two digits from the given year and printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer