Sunday, 20 June 2010

Algorithm for to find whether a given year is leap or not?

3. WAP to find whether a given year is leap or not?

To check whether a year is a leap year or not, you need to check the following 3

conditions:
1. Any year that is divisible by 400 is definitely a leap year.
2. If it is not divisible by 400, then check if it is divisible by 100, if so, then it is

NOT a leap year (even if it is divisible by 4), and
3. If the above two conditions are not satisfied we check for divisibility by 4, it it is

divisible by 4 it is a leap year.

For example,

if year = 2400, it is leap year,(Condition 1 satisfied)
but if year = 2200, is NOT a leap year, (Cond. 2 satisfied),
and if year = 2020, is a leap year, (Cond. 3 satisfied).

You can use simple if else statements to write the program.
You can read Leap Years or Leap year for better understanding of why every 400th year is

taken as a leap year and not every 100th.
Algorithm:

1. START
2. declare year of type integer.
3. use the print() to print the message "enter the year"
4. use the scanf() to read the year from keyboard
5. check the following condition with if..else statement
 (year%4==0&&year%100!=0 || year%400==0)
 (if an year is divisible by 4 AND not divisible by 100, OR is divisible by 400 then it

is called Leap Year
6. if the above condition is TRUE then Print "leap year"
7. if the above condition is FALSE then Print "not a leap year".
8. STOP
Program

No comments:

Post a Comment