w3resource logo
C Programming Exercises

C Exercises: Check whether a given year is a leap year or not

C Conditional Statement: Exercise-4 with Solution

Write a C program to find whether a given year is a leap year or not.

Sample Solution:

C Code:

#include <stdio.h>
void main()
{
    int chk_year;
 
    printf("Input a year :");
    scanf("%d", &chk_year);
    if ((chk_year % 400) == 0)
        printf("%d is a leap year.\n", chk_year);
    else if ((chk_year % 100) == 0)
        printf("%d is a not leap year.\n", chk_year);
    else if ((chk_year % 4) == 0)
        printf("%d is a leap year.\n", chk_year);
    else
        printf("%d is not a leap year \n", chk_year);
}

Sample Output:

Input a year :2016                                                                                            
2016 is a leap year.

Flowchart:

Flowchart: Check a given year is leap year or not

C Programming Code Editor:

#include <stdio.h>

void main()
{
    int chk_year;
 
    printf("Input a year :");
    scanf("%d", &chk_year);
    if ((chk_year % 400) == 0)
        printf("%d is a leap year.\n", chk_year);
    else if ((chk_year % 100) == 0)
        printf("%d is a not leap year.\n", chk_year);
    else if ((chk_year % 4) == 0)
        printf("%d is a leap year.\n", chk_year);
    else
        printf("%d is not a leap year \n", chk_year);
}

Improve this sample solution and post your code through Disqus.