Question

In your script file perform the following calculations : - Prompt the user to enter in...

In your script file perform the following calculations

: - Prompt the user to enter in a year.

- Use a nested if statement to determine if the year is a leap year by checking the following rules:

1. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.

2. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.

3. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.

4. The year is a leap year.

5. The year is not a leap year.

- Depending on the result, print out the appropriate messages where xxx is the year o 'xx is a leap year and has 366 days' or 'xx is not leap year and has 365 days'

- NOTE: to check if a number is divisible by 4, you can check if the rounded number/4 is equal to the number/4

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

#source code in c langauge:

#include <stdio.h>

int main() {

int year;

printf("enter a year:");

scanf("%d",&year);

if (year%4==0) {

if(year%100==0) {

if(year% 400 == 0){

printf("%d is a leap year and has 366 days",year);

}

else{

printf("%d is not a leap year and has a 365 days",year);

}

}

else{

printf("%d is a leap year and has 366 days",year);

}

}

else{

printf("%d is not a leap year and has 365 days",year);

}

printf("\n");

return 0;

}

#output:

#source code in matlab:

year=input("enter a year:")
if (mod(year,4)==0)
if(mod(year,100)==0)
if(mod(year,400) == 0)
sprintf("%d is a leap year and has 366 days",year)
else
sprintf("%d is not a leap year and has a 365 days",year)
end
  
else
sprintf("%d is a leap year and has 366 days",year)
end
else
sprintf("%d is not a leap year and has 365 days",year)
end

#output:

#if you need any other language or more information needed comment below..

Add a comment
Know the answer?
Add Answer to:
In your script file perform the following calculations : - Prompt the user to enter in...
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
  • Create a new MATLAB Script file named MT3P3_itname.m. In your script file perform the following calculations:...

    Create a new MATLAB Script file named MT3P3_itname.m. In your script file perform the following calculations: Prompt the user to enter an integer. Use a multiple if-elseif structure to determine the following: Confirm that the number is an integer. If not, the program displays message 1. Check if the number is divisible by 2 and displays message 2. Check if the number is divisible by 3 and displays message 3. For anything other than 1, 2, or 3, the program...

  • c++ please :) First, ask the user to enter a year (4-digit) and what week day...

    c++ please :) First, ask the user to enter a year (4-digit) and what week day does this year starts with (String) For example, the year 2018 starts with the week day "Friday". In this case, the calendar should start from January 1 which is Friday, 2018 Your program should produce a formatted calendar for the specified year and there should be a blank line after each month. Moreover, the month and the year should be centered over each month....

  • Write a perl script to accomplish following tasks: 1. Prompt user to enter their name and...

    Write a perl script to accomplish following tasks: 1. Prompt user to enter their name and age, and then calculate and display their age in days. 2. Initialize a 20-element array of numbers and print each element. 3. Get a system host name. 4. Get a web page and save it to a file. 5. List background services (daemons) on your system.

  • SOLVE USING C!!! Project objective: Conditional statements, loops, reading from file, user defined functions. **Submit source...

    SOLVE USING C!!! Project objective: Conditional statements, loops, reading from file, user defined functions. **Submit source code (LargeProg1.c) through Canvas One source code file(unformatted text) will be submitted Here is INCOMPLETE code to get started: LargeProg1.c The file name must match the assignment The code should be tested and run on a Microsoft compiler before it is uploaded onto Canvas The code must be submitted on time in order to receive credit (11:59PM on the due date) Late submissions will...

  • In this assignment we are asking the user to enter two number values, the starting and...

    In this assignment we are asking the user to enter two number values, the starting and ending numbers for our application. Having these values, we then construct a loop that will increment by one (1) from the starting number through (and including) the ending number. Within this loop we will check the current value of our number to see if it is evenly divisible by 3, then by 5, and then by both 3 and 5. We will output all...

  • C++ Loops homework Prompt the user for a desired password, input the password. Your program may...

    C++ Loops homework Prompt the user for a desired password, input the password. Your program may assume without checking that there is no input failure and that the password contains no white space. Let's say the rules for a legal password are: # chars must be in [4, 8] # digs must be >= 2 The password must contain at least one letter of each case The password must contain at least one char that's not a letter or digit...

  • 1. Prompt the user for one of the arithmetic operators ('op'): +, -, *,/, or **...

    1. Prompt the user for one of the arithmetic operators ('op'): +, -, *,/, or ** 2. Prompt the user for two input integers ('a' and'b') 3. The input numbers can be positive or negative 4. Perform the arithmetic operation using the two input numbers 5. The first entered number ('a') is the left side, the second ('b') the right side of the operation For exponentiation, the first number is the base, the second the exponent Print (display) the following...

  • Divisibility by 9 To determine if a number is evenly divisible by 9, simply add all...

    Divisibility by 9 To determine if a number is evenly divisible by 9, simply add all of the digits in that number. If the sum is divisible by 9, then the original number also is divisible by 9. For example, notice that all of the multiples of 9 from 1 through 12 (9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, and 108) contain digits which sum to 9 or 18 in every case. In another example, to...

  • An ordinal date consists of a year and a day within it, both of which are...

    An ordinal date consists of a year and a day within it, both of which are integers. The year can be any year in the Gregorian calendar while the day within the year ranges from one, which represents January 1, through to 365 (or 366 if the year is a leap year) which represents December 31. Ordinal dates are convenient when computing differences between dates that are a specific number of days (rather than months). For example, ordinal dates can...

  • This question deals with extending already existing Java code via a while loop. Ask the user...

    This question deals with extending already existing Java code via a while loop. Ask the user how many year inputs he wants to check - an integer. Assume that the user always gives an input which is between 1 and 5 (inclusive). Next, ask the user for K number of year inputs where K = the number user has given as input before (inside a while loop). Check for each year input whether that year is a leap year or...

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