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

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

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

You may also want to read: Check leap year without 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 year:\n");
  scanf("%d",&year);
  if(year%4==0) {
    if(year%100==0) {
      if(year%400==0)
      printf("%d is a century leap year",year);
      else
      printf("%d is a century year but not a leap year",year);
    }
    else
    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