WAP in C to check whether the entered year is leap year or not using else if

Back to Posts

WAP in C to check whether the entered year is leap year or not using else if

Write a program in C to check whether the entered year is a leap year or not using nested else if.

You may also want to read: Check leap year using nested if.

A year called a leap year, if that year is divisible by 4 but not 100 and also if that year is divisible by 400. Else that year is not a leap year.

#include<stdio.h>

int main() {
  int year;
  printf("Enter the year:\n");
  scanf("%d",&year);
  if(year%4==0 && year%100!=0)
  printf("%d is a leap year",year);
  else if(year%400==0)
  printf("%d is a leap year",year);
  else
  printf("%d is not a leap year",year);
  return 0;
}

Output:

leap year output
leap year output

Share this post

Back to Posts