112k views
5 votes
2.13 LAB: Branches: Leap Year

A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the
difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The
requirements for a given year to be a leap year are:
1) The year must be divisible by 4
2) If the year is a century year (1700, 1800, etc.), the year must be evenly divisible by 400
Some example leap years are 1600, 1712 and 2016.
Write a program that takes in a year and determines whether that year is a leap year.
Ex If the input is
1712
the output is
1712 13 leap year.
Ex If the nouts
1913
the outoutis
1913 not leap year.
Written is Coral Language

2 Answers

3 votes

Answer:

integer userInput

userInput = Get next input

if userInput % 400 == 0

Put userInput to output

Put " is a leap year" to output

else

if userInput % 4 == 0

Put userInput to output

Put " is a leap year" to output

else

Put userInput to output

Put " is not a leap year" to output

Step-by-step explanation:

I don't know what is so special about Coral but here we go. I couldn't find and IDE that supported Coral so I just used their Coral simulator on their website. The first if statement on line 5 determines if the number is divisible by 400. If so, the leap year is on a century year e.g 1900 1800. If not, the else statement will be executed and the second if statement will execute. If the number is divisible by 4, it is a leap year. If not, the else statement gets executed in which case the number was not a century leap year or a leap year. After that the program terminates.

Hope this helped :) If it didn't let me know and I do my best to find out what went wrong.

Have a good day :)

User YanivGK
by
5.3k points
3 votes

Below is an example of a program written in Coral Language that takes a year as input and determines whether it is a leap year or not.

func isLeapYear(year: int) -> bool {

if (year % 4 == 0) {

if (year % 100 == 0) {

return year % 400 == 0;

}

return true;

}

return false;

}

func main() {

let year: int = input("Enter a year: ");

if (isLeapYear(year)) {

print("\(year) is a leap year.");

} else {

print("\(year) is not a leap year.");

}

}

User Milkovsky
by
4.9k points