Here’s a simple C program to check whether a given year is a leap year or not.
This program prompts the user to enter a year, and then it checks whether the entered year is a leap year or not. The logic for checking leap years is as follows:
- If a year is divisible by 4 and not divisible by 100, or
- If a year is divisible by 400
Then it is a leap year. Otherwise, it is not a leap year. The program displays the result accordingly.
Program :
#include<stdio.h>
#include<conio.h>
int main()
{
int year;
printf(“Enter a year to check if it is a leap year : “);
scanf(“%d”,&year);
if(year%400==0)
{
printf(“%d is a leap year.\n”,year);
}
else if(year%100==0)
{
printf(“%d is not a leap year.\n”,year);
}
else if(year%4==0)
{
printf(“%d is a leap year.\n”,year);
}
else
{
printf(“%d is not a leap year.\n”,year);
}
}