C Program to Check Leap Year

C Program to Check Leap Year

Q:-Write a C program to find whether a given year is a leap year or not. In this example, you will learn to check whether the year entered by the user is a leap year or not. A leap year is exactly divisible by 4 except for century years (years ending with 00). The century year is a leap year only if it is perfectly divisible by 400.

#include<stdio.h>
#include<conio.h>

void main() 
{
 int year;  
 clrscr(); 

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

    if( (year % 4 == 0 && year % 100 != 0 ) || (year % 400 == 0) )
    {
        printf("%d is a leap year", year);
    }

    else
    {
        printf("%d is not a leap year", year);
    }
getch();
 }

Output

To determine whether a year is a leap year or not, we use the following algorithm:

Check if the year is divisible by 4. If it is, go to step 2, otherwise, go to step 3.
Check if the year is divisible by 100. If it is, go to step 3, otherwise, the year is a leap year
Check if the year is divisible by 400. If it is, then the year is a leap year, otherwise, the year is not a leap year.

TOP