Challenge: Seconds to Time
Completed
Read a number of seconds and print it as hours, minutes and seconds.
Input
One integer: the number of seconds.
Output
H hours, M minutes, S seconds
Example
Input
3725
Output
1 hours, 2 minutes, 5 seconds
Editor
C
Hints
An hour has 3600 seconds.
Use % to find what is left over after the full hours.
Solution explanation
/ counts the full hours; % keeps the rest, which we split into minutes and seconds the same way.
Show solution
#include <stdio.h>
int main() {
int total;
scanf("%d", &total);
int hours = total / 3600;
int minutes = (total % 3600) / 60;
int seconds = total % 60;
printf("%d hours, %d minutes, %d seconds\n", hours, minutes, seconds);
return 0;
} Output
Answer
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module