Code:
#include <stdio.h>
#define MINS_HR 60 //define minutes per hour
#define SECS_MIN 60 //define seconds per minute
int main(void) {
int total;
int h, m, s;
printf("How many seconds whould you like to convert?\n");
scanf("%d", &total);
h = (total / (MINS_HR * SECS_MIN));
if (h >= 1) {
total = total - (MINS_HR * SECS_MIN);
if (h <= 0) {
h = 0;
}
}
m = (total / SECS_MIN);
if (m >= 1) {
total = (total - (SECS_MIN * m));
if (m <= 0) {
m = 0;
}
}
s = total;
printf("%d:%d:%d", h, m, s);
}
this program is supposed to convert seconds to hours:minutes:seconds...for example, 4000 seconds would be 01:06:40.
is this the most efficient way? i've noticed that it doesn't work for all inputs. higher amount of seconds, the less accurate the output is. please advise.