Sat Jun 09 2018

Leap Year

C Programming882 views

File Name: leap-year.c

#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!
Reference:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.