Explore
ProGrad Programs
About Us

Edit
Reply




Edit

C program to check leap year

Published on 06 Mar 2020

C program to check if a given year is a leap year or not is given below. The given year is a leap year if it is exactly divisible by 4. But in certain cases the century year is also a leap year, only if they are divisible by 400. This has been used in the below logic to implement the program.


include <stdio.h>
int main()
{
int year;
printf("Enter a year: \n");
scanf("%d",&year); 
if(year%4 == 0) 
{
if(year%100 == 0) 
{ 
if (year%400 == 0)    //If a year is multiple of 400, then it is a leap year 
printf("%d is a leap year.", year);
else 
printf("%d is not a leap year.", year); 
}
else 
printf("%d is a leap year.", year ); 
} 
else 
printf("%d is not a leap year.", year); 
return 0; 
}


 

Output:


Enter a year: 2012
2012 is not a leap year.
If you have any feedback about this article and want to improve this, please write to enquiry@faceprep.in