matlab help !! Q2. Use while loop to get how many full days, full hours, full mi
ID: 3708657 • Letter: M
Question
matlab help !!
Q2. 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(s), 12 hr(s), 1 min(s) and 7 sec
275 seconds contains 4 min(s) and 35 sec
Explanation / Answer
t = input('Enter number of seconds');
d = t/24*3600;
H=t/3600;
M=(t - H*60*60 )/60;
S=t - H*60*60 -M*60;
time='';
if d > 0
time = sprintf('%s %d hrs', time, d);
end
if H > 0
time = sprintf('%s %d hrs', time, H);
end
if M > 0
time = sprintf('%s %d min', time, M);
end
if S > 0
time = sprintf('%s %d sec', time, S);
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.