Dremendo Tag Line

Check leap year in C

if else - Question 4

In this question, we will see how to check if a year is a leap year or not in C programming using the if else statement. To know more about if else statement click on the if else statement lesson.

Q4) Write a program in C to input a year and check if it is a leap year or not. A leap year is a year which is either divisible by 400 or it is not divisible by 100 but divisible by 4. Make use of logical operators (&& ||) to solve this question.

Program

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

int main()
{
    int y;
    printf("Enter a year ");
    scanf("%d",&y);
    if(y%400==0 || (y%100!=0 && y%4==0))
    {
        printf("Leap year");
    }
    else
    {
        printf("Not leap year");
    }
    return 0;
}

Output

Enter a year 2020
Leap year
video-poster