Learn about Check Leap Year Using nested if-else in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Check Leap Year Using nested if-else
If a year is said to be leap year then it should meet some conditions. The below program uses nested if-else conditions to test the conditions and prints the result.
Program:
#include<stdio.h>
int main()
{
int year;
printf("Enter Year:");
scanf("%d",&year);
if(year%4==0)
{
if(year%100==0)
{
if(year%400==0)
printf("%d is leap year.",year);
else
printf("%d is not leap year.",year);
}
else
printf("%d is leap year.",year);
}
else
printf("%d is not leap year.",year);
return 0;
}
Output:
Enter Year: 2016
Leap Year.
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
Leap Year Program in C Using if-else statement
C Program to Check Vowel or Consonant using predefined function