Header Ads Widget

C program to check whether a year is leap year or not

 C program to check whether a year is leap year or not

Given a year , write a program to check whether it is leap year or not . So first we have to know that what is leap year .

Leap year : - 
  • A leap year is a calendar year that contains an additional day added to keep the calendar year synchronized with the astronomical year or seasonal year
  • Generally Year which is divided by 4 is know as leap year . but the year which are divided by 100 for these year we have to check that whether it is divided by 400 or not . if it is then the year is leap year .
Sample input :
2001
Sample output:
2001 is not a leap year 

 C program to check whether a year is leap year or not

The objective of the code is to check that the year is leap year or not .

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

return 0;
}


Output:-

1600
1600 is a leap year



Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-

Post a Comment

0 Comments