C Program to Extract Last two Digits of a given Year

«
»

This is C Program to extract last two digits of a given year.

Problem Description

This program takes any year as input and prints its last two digits.

Problem Solution

1. Take any year as input.
2. Divide the input by 100 and obtain its remainder.
3. The remainder got is the output.

advertisement
Program/Source Code

Here is source code of the C Program to extract last two digits of a given year. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C Program to Extract Last two Digits of a given Year
  3.  */
  4. #include <stdio.h>
  5.  
  6. int main()
  7. {
  8.     int year, yr;
  9.  
  10.     printf("Enter the year ");
  11.     scanf("%d", &year);
  12.     yr = year % 100;
  13.     printf("Last two digits of year is: %02d", yr);
  14.     return 0;
  15. }
Program Explanation

1. Take any year as input and store it in the variable year.
2. Divide the variable year by 100 and obtain its remainder. Store the remainder in the variable yr.
3. Print the variable yr as output.

advertisement
Runtime Test Cases
Output:
Enter the year 2012
Last two digits of year is: 12

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics, go to C Programming Examples.

advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn