How to find a leap year using C language?



Leap year is a year that consists of 366 days. For every four years, we will experience a leap year.

The logic we will implement to find whether the given year by the user through the console is a leap or not −

if (( year%400 == 0)|| (( year%4 == 0 ) &&( year%100 != 0)))

If this condition is satisfied, then the given year is a leap year. Otherwise, it is not.

Example

Following is the C program to check leap year with the help of If condition −

 Live Demo

#include <stdio.h>
int main(){
   int year;
   printf("Enter any year you wish 
");    scanf(" %d ", &year);    if (( year%400 == 0)|| (( year%4 == 0 ) &&( year%100 != 0)))       printf("
%d is a Leap Year.
", year);    else       printf("
%d is not the Leap Year.
", year);    return 0; }

Output

When the above program is executed, it produces the following result −

Enter any year you wish
2045
2045 is not the Leap Year.

Advertisements