Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

02. Use while_ loop to get how many full days, full hours, full minutes and seco

ID: 3916310 • Letter: 0

Question

02. Use while_ loop to get how many full days, full hours, full minutes and seconds in a given number of seconds. Display the days, hours, minutes and the remaining seconds. Display only the units with non-zero values. Sample outputs: 129667 seconds contains 1 day (a), 12 hr (a), 1 min (s) and 7 sec 3601 seconds containg 1 hein) and 1 sec 275 seconds contains 4 min(s) and 35 sec

Explanation / Answer

SECS_IN_DAY = 24*60*60 SECS_IN_HOUR = 60*60 SECS_IN_MIN = 60 days = 0 hours = 0 mins = 0 secs = 0 inputSecs = 129667 while inputSecs > 0 if inputSecs > SECS_IN_DAY days += 1 inputSecs = inputSecs - SECS_IN_DAY elseif inputSecs > SECS_IN_HOUR hours += 1 inputSecs = inputSecs - SECS_IN_HOUR elseif inputSecs > SECS_IN_MIN mins += 1 inputSecs = inputSecs - SECS_IN_MIN elseif inputSecs > 1 secs += 1 inputSecs = inputSecs - 1 end end s = "" fprintf("%d seconds contains ") if days > 0 fprintf("%s%d day(s)",s, days) s = ", " end if hours > 0 fprintf("%s%d hr(s)",s, hours) s = ", " end if mins > 0 fprintf("%s%d min(s)",s, mins) s = ", " end if secs > 0 fprintf("%d day(s), ", secs) s = ", " end ======================== This is how this code should be written, there might be small mistake in terms of syntax, since i dont have a platform right now to run the code.. but algorithm is for sure correct. Thanks!