Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have homework questions and I want to double check everything before I submit so I would like someone else's opinion. The class is in

I have homework questions and I want to double check everything before I submit so I would like someone else's opinion. The class is in programming language C. Thank you!

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Question 1 20 pts Normally, in the Gregorian calendar, every year has 365 days. Since the Earth takes a little longer than 365 days to orbit the Sun, every so often we have an extra day in February (the "leap" year) to correct for this issue. The following is the rule for when are leap years according to the US Naval Observatory. "Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. For example, the years 1700, 1800, and 1900 are not leap years, but the years 1600 and 2000 are." Write a function isLeap Year, that takes the year as an integer argument and returns 1 if it is a leap year and O if it is not a leap year. Make sure your function is syntactically correct. You can assume that the year will be greater than 0 HINT: You could decompose the above statement to: if year not divisible by four -> common year else if year is not divisible by 100 -> leap year else if year is not divisible by 400 -> common year else -> leap year BIU A - A - Ix E333 x E N Vw Moto G V 11 12pt HTML Editore 5 = Para Question 2 20 pts In this question, please write a function daysInMonth, that takes the year and month as two integer arguments and returns the number of days in that month. Use the function "isLeap Year" from the previous problem (you can assume that it works) to accommodate for leap years. Make sure your function is syntactically correct. You can assume that the year will be greater than 0 and that the month will take the values (1-12]. HINT: Days in the month can be 28,29,30, or 31. Think about the cases each of these occur. x BIU A - A - IX E N N Vx neto E HTML Editora := = Para G V T 12pt Question 3 20 pts Convert the following for loop to an equivalent while loop: int index = 0; int testArray[10]; for (index = 0; index 0) testArray[index] *= testArray[index-1]; What are the final values inside testArray? Write your answer in [0,1,2,3,4,5,...] format. B x I VA - A DP N - Ix E Va to E ? x 12pt HTML Editore := = Para Question 4 20 pts Please write a function printFibonacci, that takes the number of terms to print as an integer argument and returns nothing. Use UARTprintf to print out each of the Fibonacci sequence. Use an iterative for loop for this problem. You can assume that all the necessary includes are already done (just right the function) and that the number of terms is greater than 0. HINT: Fibonacci sequence is Fib(n) = Fib(n-1) + Fib(n-2) where Fib(O) = 0 and Fib(1) = 1. For example, if printFibonacci receives 5 as input, it should print the sequence "O, 1, 1, 2, 3" HTML Editora BI VA - A - Ix 3 3 3 3 3 x x := = N Vx Moto G V D 1 12pt - Para E Question 5 20 pts There are two errors in the following code, please indicate what line number they are on and how to fix it. It may be functional or syntactical. The following code finds the two highest values (saves highest in max1 and second highest in max2) in an array called testArray. 1. int testArray[100]; 2. int index = 0; 3. int max1 = 0; 4. int max2 = 0; 5. for(index = 0; index max1) 8. { max1 = testArray[index]; 10. max2 = max1; 11. } 12. else if (testArray[index] > max2); 13. { 14. max2 = testArray[index]; 15. } 16. } ma HTML Editore BI VA - A - Ix 5 3 3 3 3 x x := = E N Vx neto G V 12pt - Para

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions