Ok, first of all why we need to check if a year is leap
year or not?
Answer is simple! A leap year contains an extra day
(i.e. 29th February).
So, as per my conclusion if we select a date from a leap
year and before 1st March i.e. in between 1st January
& 29th February (both dates including) then we need to go one
day back from the day we calculated to get the exact day!
Didn't get the thing???? Don’t worry; you will be clear with it as I will explain
it with an example in the next chapters.
First we will see how to find if a year is a leap year
or not. And it is simple to find one. For that you will have to check if last
two digits in a year (YYYY) are 00 or not. Based on that following are
the two cases to know if a year is leap year or not:
Case 1. If last two digits in year
are other than 00
If last two digits in year are other
than 00 (as in 1996) then check if the number formed by these last two digits (96) is
completely divisible by 4 i.e. remainder is zero (or we can say these last two
digits form a number that is present in the multiplication table of 4).
If above condition is true then the
given year is a leap year.
Example: 1996 is a leap year as 96 is
completely divisible by 4 i.e. remainder is zero (96 is present in the multiplication
table of 4).
If above condition is false then the
given year is not a leap year.
Example: 1997 is not a leap year as
97 is not completely divisible by 4 i.e. remainder is not zero (97 is not
present in the multiplication table of 4).
Case 2. If last two digits in year
are 00
If last two digits in year are 00 (as
in 2000) then check if the number formed by first two digits (20) in the year is completely divisible by 4 i.e.
remainder is zero (or we can say these last two digits form a number that is
present in the multiplication table of 4).
If above condition is true then the
given year is a leap year.
Example: 2000 is a leap year as 20 is
completely divisible by 4 i.e. remainder is zero (20 is present in the
multiplication table of 4).
If above condition is false then the
given year is not a leap year.
Example: 2100 is not a leap year as
21 is not completely divisible by 4 i.e. remainder is not zero (21 is not
present in the multiplication table of 4).
Now, we will summarize above two
cases:
Case 1. If year is like YYYY (i.e.
last YY are not 00) then–
Check if last YY (YYYY) is completely divisible by 4.
If yes then YYYY is a leap year.
If no then YYYY is not a leap year.
Case 2. If year is like YY00 (i.e.
last YY are 00) then–
Check if first YY (YYYY) is completely divisible by 4.
If yes then YYYY is a leap year.
If no then YYYY is not a leap year.
That is to it!
No comments :
Post a Comment