Leap Year

C Programming

C Programming Examples

#include<stdio.h>

int main() {
	int year;
	printf("Enter a year to check that it's a Leap year or not:\n");
	scanf("%d", &year);
	if(year%4 == 0) {

		/* Checking for century year */
		if(year%100 == 0) {
			if(year%400 == 0)
				printf("%d is a leap year!\n",year);
			else
				printf("%d is not a leap year!\n",year);
		}
		else
			printf("%d is a leap year!\n",year);
	}
	else
		printf("%d is not a leap year!\n",year);
	return 0;
}


          /****** Output ******/
          

Enter a year to check that it's a Leap year or not:

2004

2004 is a leap year!


-------------------------------


Enter a year to check that it's a Leap year or not:

1900

1900 is not a leap year!

Learn more about Leap Year