Problem
Statement
In
this program we will code a basic program to check whether an year is a leap
year or not.
Code
#include
bool leapyear(int year)
{
if(((year % 4 == 0) && (year % 100!= 0)) ||
(year%400 == 0))
{
return true;
}
return false;
}
int main()
{
int year;
printf("Enter
the Year :");
scanf("%d",&year);
if(leapyear(year))
{
printf("%d is
a Leap Year.",year);
}
else
{
printf("%d is
not a Leap Year.",year);
}
return 0;
}
Output
Enter
the Year : – 2020
2020
is a Leap Year.
Explanation
To check whether a year is a
leap year or not,we rely on two conditions :
1.Year should be divisible by 4 and not divisible by 100.
2.Year should be divisible by 400.


0 Comments