C Program to Find if a given Year is a Leap Year or not

c program to check leap year

This question is asked many times in exams to : write a c program to check whether the given year is leap year or not ? but most of them fail to write a write logic so here we are with the answer to your question

c program to check leap year

Problem Description

This program takes a year as input and find whether a given year is leap year or not.

Solution

1. Take a year as input.
2. Check whether a given year is divisible by 400.
3. Check whether a given year is divisible by 100.
4. Check whether a given year is divisible by 4.
5. If the condition at step 2 and 4 becomes true, then the year is a leap year.
6. If the condition at step 3 becomes true, then the year is not a leap year.

Program/Source Code

Here is source code of the c program to check whether a year is leap year or not. The C program is successfully compiled and run on a Linux system. you can check and run the code in the compiler here and verify the code working. Also you can check the output below the code

[php]
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();

printf("enter a year= ");
scanf("%d",&year);
if((year%4==0&&year%100!=0)||(year%400==0))
{
printf("%d is a leap year",year);
}

else
{
printf("year is not a leap year",year);
}

getch();
}
[/php]

Output 1

Enter a year: 1901
1901 is not a leap year.

Output 2

Enter a year: 2016
2016 is a leap year.

live demo :- ¬† ¬† ¬†download code : –

Check out these related examples:
C Program to Check Armstrong Number

Leave a Reply

avatar
  Subscribe  
Notify of