Question

FINDING THE LEAP YEARS (14 points) From Wikipedia, A leap year (also known as an intercalary year or bissextile year) is a cAddition problem (14 points) Write a program to create a random addition quiz and check if the user has entered the correct a

0 0
Add a comment Improve this question Transcribed image text
Answer #1

leapyear.m

******************************************************************************************************************************************

year = input("Enter the year:") #ask for the input

if mod(year,4)!=0 #if year is not divisible by 4
fprintf('Not a leap year.\n')
elseif mod(year,100)!=0 #if year is not divisible by 100
fprintf('A leap year.\n')
elseif mod(year,400)!=0 #if year is not divisible by 400
fprintf('Not a leap year.\n')
else #else
fprintf('A leap year.\n')
end

******************************************************************************************************************************************

Screenshot of the code:

year = input(Enter the year:) #ask for the input N 5 6 if mod (year, 4)! =0 #if year is not divisible by 4 fprintf(Not a l

Output:

octave:9> leapyear Enter the year:> 1900 year = 1900 Not a leap year. octave:10> leapyear Enter the year:> 2012 year = 2012 A

adding.m

******************************************************************************************************************************************

a = randi([0 9],1,1); #generate a random number between 0 and 9
b = randi([0 9],1,1); #generate another random number between 0 and 9

if input(['What is ',num2str(a),' + ',num2str(b),' = '])==a+b #check if the input number is equal to the sum of the a and b
fprintf('Correct!\n')
else
fprintf('Wrong!\n')
end

******************************************************************************************************************************************

Screenshot of the code:

a - randi(10 91,1,1); #generate a random number between 0 and 9 b = randi([@ 9],1,1); #generate another random number betweenOutput:

octave:9> adding What is 2 + 2 = > 4 Correct! octave:10> adding What is 6 + 3 = > 6 Wrong!

Add a comment
Know the answer?
Add Answer to:
FINDING THE LEAP YEARS (14 points) From Wikipedia, "A leap year (also known as an intercalary...
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
  • #1 Write a MATLAB script to solve: Leap Year Program (practice your IF statements!) Write a...

    #1 Write a MATLAB script to solve: Leap Year Program (practice your IF statements!) Write a code to determine if a year is considered a leap year or not? Display to the screen if the year is a leap year or not. Use num2str() and display() or fprintf(). In the Gregorian calendar three criteria must be taken into account to identify leap years: The year is evenly divisible by 4 (Exceptions 1700, 1800, and 1900); If the year can be...

  • 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: All years evenly divisible by 400 are leap years. Years evenly divisible by 100 but not by 400 are not leap years. Years divisible by 4...

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

  • solve in python In the planet Utopia a year is a leap year in this century...

    solve in python In the planet Utopia a year is a leap year in this century and previous century between years 45 and 450, if it is divisible by 30, Write a program that calculates whether a given year is a leap year in UTOPIA. Input: The year in 4 digits between 45 and 450. You need to check the input year. When the input year is less than 45 or greater than 450 then use a loop to generate...

  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:             0 Sunday                     1 Monday                   2 Tuesday                   3 Wednesday       4 Thursday                 5 Friday                      6 Saturday Your program should...

  • PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program tha...

    PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program that reads a values for hour and minute from the input test file timeData.txt . The data read for valid hour and valid minute entries. Assume you are working with a 24 hour time format. Your program should use functions called validateHour and validateMinutes. Below is a sample of the format to use for your output file  timeValidation.txt :   ...

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

  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. This program needs to use Switch Case in order to call the methods and format to print each month. The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:      ...

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

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

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