Write a C program to check Leap year or Not

C Program to Check Leap Year or Not

Here’s a simple C program that checks whether a given year is a leap year or not.

Explanation:

  • This program is designed to check whether a given year is a leap year or not.
  • It prompts the user to enter a year.

Checking leap year:

  • A leap year is divisible by 4 but not divisible by 100 unless it is divisible by 400.
  • The program uses the logical OR (||) to combine these conditions.
  • After checking the conditions, the program prints whether the entered year is a leap year or not.

How it works:

  • If the entered year satisfies the leap year conditions, it will print that it is a leap year.
  • If the entered year does not satisfy the conditions, it will print that it is not a leap year.

Program:

#include <stdio.h>
int main(){
int year;
printf("Enter a year :");
scanf("%d",&year);
if(((year%400==0 )||(year%100!=0))&&(year%4==0))
printf("%d is a leap year.\n",year);
else
printf("%d is not a leap year.\n",year);
return 0;
}

Output 1:

Enter a year: 1997
1997 is not a leap year.

Output 2:

Enter a year: 2004 2004 is a leap year 

In conclusion, the provided C program efficiently determines whether a given year is a leap year. It employs the logical conditions of divisibility by 4, non-divisibility by 100 (unless divisible by 400) to ascertain leap years. This compact program serves as a practical tool for identifying leap years, crucial in various calendrical applications. Its simplicity makes it easily adaptable, while its logic ensures accurate leap year determinations.

Overall, the program offers a concise and effective solution for leap year checking, catering to scenarios where knowledge of leap years is essential for accurate time calculations and scheduling.

Scroll to Top