ADVERTISEMENT
ADVERTISEMENT

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

Here, we are going to learn how to extract the last two digits from a given year using C program?
Submitted by Nidhi, on August 27, 2021

Problem Solution:

Read the year from the user, and extract the last two digits, and print on the screen.

Program:

The source code to extract the last two digits from a given year is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to extract last two digits
// from a given year

#include <stdio.h>

int main()
{
    int year = 0;
    int res = 0;

    printf("Enter year: ");
    scanf("%d", &year);

    res = year % 100;

    printf("Result is: %02d", res);

    return 0;
}

Output:

RUN 1:
Enter year: 2021
Result is: 21

RUN 2:
Enter year: 1988
Result is: 88

Explanation:

Here, we read the year from the user and extracted the last two digits from the input year using the "%" operator and assigned the result into the res variable, and printed the result on the console screen.

C Basic Programs »


ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

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.