C program to check leap year

05 min read

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: ");
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.
POST A NEW COMMENT
     
  • Input (stdin)

    Output (stdout)


    Input (stdin)

    Your Output (stdout)

    Expected Output

    Compiler Message

    Input (stdin)

    2    3

    Your Output (stdout)

    5

    Expected Output

    5

    Compiler Message

    5

    Error