Check year is leap year or not in c

Check year is leap year or not in c

Leap Year:

A leap year is a year that has one extra day (February 29), making it 366 days long instead of the usual 365 days. Leap years are added to keep our calendar in sync with the Earth's orbit around the sun, which takes approximately 365.242 days

Calendar of Leap Year:

Check year is leap year or not in c


Code:

// check year is leap year or not
// with the help of operator in c
#include <stdio.h>
int main()
{
   int year;
   printf("Enter year: ");
   scanf("%d",&year);
   //Leap year check
   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);
   }
    return 0;
}

Explanation:

A year is a leap year if:

It is divisible by 4, but not divisible by 100; OR
It is divisible by 400.
The condition (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0) for check year is leap year or not.

Example Run:

Enter year: 2020
2020 is a leap year.

Enter year: 2021
2020 is not a leap year.

*

Post a Comment (0)
Previous Post Next Post