Decision Making Statement | Part-2
Check the year is leap year or not. #include<stdio.h> int main() { int year; printf("Enter any year: "); scanf("%d",&year); if(year % 100 == 0) { if (year % 400 == 0) { printf("%d is a leap year",year); } else { printf("%d is not a leap year",year); } }else { if(year % 4 == 0) { printf("%d is a leap year",year); } else { printf("%d is not a leap year",year); } } return 0; } Output Enter any year: 1996 1996 is leap year Enter any year: 2001 2001 is no a leap year Enter any year: 1800 1800 is not a leap year Program Explained You know the year which is divisible by 4 is called leap year, but what about the century? Each century is divisible by 4. but to check whether the century is a leap year or not we have to check its divisibility by 400. So the logic to check the year is a leap or not: First check the year is a century if the year is century then check its divisibili