Find Leap Year in C language using Nested If statements

In this post, I am going to write a C program with nested if statements to find the Leap year.

This example C program is very much useful for school students and for the beginners.

// include the header files
#include <stdio.h>
#include <stdlib.h>

void main() {
	
  int x;
  printf("Enter a year:");
  scanf("%d", & x);
  
  // nested if statements to check Leap year 
  if (x % 4 == 0) {
    if (x % 100 == 0) {
      if (x % 400 == 0) {
        printf("%d is a leap year", x);
        exit(0);
      } else {
        printf("%d is not a leap year", x);
        exit(0);
      }
    } else {
      printf("%d is a leap year", x);
    }
  } else {
    printf("%d is not a leap year", x);
  }

}

I believe this post would have helped you to understand how to write a nested If statement in C language and also how to find leap year.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top