Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop an algorithm that determines if a given year is a leap year in the Grego

ID: 3791930 • Letter: D

Question

Develop an algorithm that determines if a given year is a leap year in the Gregorian calendar. A year is a leap year (and therefore has 29 days in February) if its number is divisible by 4, unless it is also divisible by 100 but not 400. Number 0 does not correspond to a year. The algorithm must specify that the program will display a special error message if 0 is entered. Yet another error message should be displayed for any other input value less than 1582, the year when the Gregorian calendar was adopted. Document your algorithm in Microsoft Word using pseudocode.

Explanation / Answer

START
  
Step 1 Take integer variable year
            year <- input

Step 2 Check if year is divisible by 4 but not 100, DISPLAY "leap year"
            If year%4=0 && year%100 !=0 then
                print "leap year"

Step 3 Else Check if year is divisible by 400, DISPLAY "leap year"
            Else If year%400 = 0 then
                print "leap year"

Step 4 Otherwise, DISPLAY "not leap year"
            Else
                print "not leap year"

STOP