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.
Test Data :
2016
Expected Output
:
2016 is a leap year.

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);
}

Flowchart :

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.

﻿