Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C programming Basic Input, Output, if else, Ternary Operator based Programs

Similar questions


need a help?


find thousands of online teachers now
C program to perform the ATM Transactions... >>
<< C program to calculate the addition of two complex...