Question

Write a program that accepts a year and determines whether the year is a leap year....

Write a program that accepts a year and determines whether the year is a leap year. Use the mod function. The output should be the variable extra_day, which should be 1 if the year is a leap year and 0 otherwise. The rules for determining leap years in the Gregorian calendar are as follows:

  1. All years evenly divisible by 400 are leap years.
  2. Years evenly divisible by 100 but not by 400 are not leap years.
  3. Years divisible by 4 but not by 100 are leap years.
  4. All other years are not leap years.

For example, the years 1800, 1900, 2100, 2300, and 2500 are not leap years, but 2400 is a leap year.

Solve using Matlab

1 0
Add a comment Improve this question Transcribed image text
Answer #1
year = input("Enter year: ");
extra_day = mod(year, 4) == 0 && (mod(year, 400) == 0 || mod(year, 100) ~= 0);
fprintf("Extra day = %d\n", extra_day)

Enter year: > 2019 Extra day = 0

Add a comment
Know the answer?
Add Answer to:
Write a program that accepts a year and determines whether the year is a leap year....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Repeat SPIDER 2 Q1, but write a function that accepts a year as an input argument...

    Repeat SPIDER 2 Q1, but write a function that accepts a year as an input argument and determines whether that year is a leap year. The output should be the variable extra_day, which should be 1 if the year is a leap year and 0 otherwise. Spider two Q1 1. Write code to determine whether a year is a leap year. Use the mod function. The rules for determining leap years in the Gregorian calendar are as follows: 1. All...

  • Use the program MATLAB to answer the following question:Use the program MATLAB to answer the following...

    Use the program MATLAB to answer the following question:Use the program MATLAB to answer the following question: KE Mona File Use The Program MATLA x 0 Info Assignment 8, Matlab, spring 2017.docx O Download Close box 2/2 5. Write a program that accepts a year and determines whether the year is a leap year. Use the mod function. The output should be the variable extra day, which should be 1 if the year is a leap year and 0 otherwise....

  • In Python 3 please 3.28 LAB: Leap year A year in the modern Gregorian Calendar consists...

    In Python 3 please 3.28 LAB: 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...

  • FINDING THE LEAP YEARS (14 points) From Wikipedia, "A leap year (also known as an intercalary...

    FINDING THE LEAP YEARS (14 points) From Wikipedia, "A leap year (also known as an intercalary year or bissextile year) is a calendar year containing one additional day (or, in the case of lunisolar calendars, a month) added to keep the calendar year synchronized with the astronomical or seasonal year." In the Gregorian calendar, which is in use today, to determine leap year: A year is a leap year if it is divisible by 400 Or it is divisible by...

  • leap year C++

    the instructions are: 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 42) If the year is a century year...

  • CIS22A Homework 6 Topic: Chapter 4 & 5 Purpose: Determine if a year is a leap...

    CIS22A Homework 6 Topic: Chapter 4 & 5 Purpose: Determine if a year is a leap year Create a new C++ project titled “HW 6” in the CodeBlocks IDE. Use the “Console Application” project option. Over time, the calendar we use has changed a lot. Currently, we use a system called the Gregorian Calendar and it was introduced in 1582. The algorithm to determine if a year is a leap year is as follows: Every year that is exactly divisible...

  • please follow format of example output, do in python A year in the modern Gregorian Calendar...

    please follow format of example output, do in python 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...

  • A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes...

    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...

  • A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes...

    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...

  • Complete task using python code From definitions file: month = ‘February’ year = 1200 Problem 2:...

    Complete task using python code From definitions file: month = ‘February’ year = 1200 Problem 2: Leap Years (2 Points) Your task is to write a program that takes in both a month and year (defined in the definitions file) and outputs the number of days for that month. It should take into account whether the year is a leap year or not. The resulting number of days in a given month/year combo is to be assigned to the variable...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT