ADVERTISEMENT
ADVERTISEMENT

Rust program to extract the last two digits from a given year

Given a year, we have to extract the last two digits from a given year using the Rust program.
Submitted by Nidhi, on October 02, 2021

Problem Solution:

Here, we will read a year from the user. Then we will extract the last two digits from the given year.

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.

// 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.

Rust Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.