C

C Program For Checking The Leap Year

This program determines whether or not the input year is a leap year.

Example: Leap Year Checking Software

Using the following mathematical logic, you can determine whether a year is a leap year or not:
Year of the Leap:
A leap year is one that is divisible by 4, 100, and 400.
A leap year is one that is divisible by four but not by one hundred.
It’s not a leap year:
A year is not a leap year if it is not divisible by four.
A year is not a leap year if it is divisible by 4 and 100 but not by 400.
Let us put this logic into a C program. To understand this program, you should be familiar with the following C programming topics:

  • Programming in C If…then, Nested if…then
#include <stdio.h>
int main()
{
    int y;

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

    if(y % 4 == 0)
    {
    	//Nested if else
        if( y % 100 == 0)
        {
            if ( y % 400 == 0)
                printf("%d is a Leap Year", y);
            else
                printf("%d is not a Leap Year", y);
        }
        else
            printf("%d is a Leap Year", y );
    }
    else
        printf("%d is not a Leap Year", y);

    return 0;
}

Output:

Enter year: 1991
1991 is not a Leap Year

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button