ADVERTISEMENT
ADVERTISEMENT

Ruby program to extract the last two digits from the given year

Ruby Example: Write a program to extract the last two digits from the given year.
Submitted by Nidhi, on November 30, 2021

Problem Solution:

In this program, we will read a year from the user. Then we will extract the last two digits from a given year and assign the result to another variable.

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.

# Ruby program to extract the last two digits 
# from the given year

Year = 0;
Res  = 0;

print "Enter year: ";
Year = gets.chomp.to_i;  

Res = Year % 100;

print "Result is: ", Res;

Output:

Enter year: 2022
Result is: 22

Explanation:

In the above program, we created two variables Year and Res,  that are initialized with 0. Then we read the value of Year from the user. Then we extracted the last 2 digits from a given year and assigned it to the Res variable. After that, we printed the value Res variable.

Ruby Basic Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



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