Challenge: Digital Clock
Completed
Create int variables hours = 7, minutes = 5 and seconds = 9, and print them like a digital clock, with two digits each:
07:05:09
Input
None.
Output
07:05:09
Example
Output
07:05:09
Editor
C
Hints
%02d prints at least 2 digits, filling with a zero.
Use one printf with three placeholders.
Solution explanation
The 0 in %02d pads with zeros and the 2 is the width.
Show solution
#include <stdio.h>
int main() {
int hours = 7;
int minutes = 5;
int seconds = 9;
printf("%02d:%02d:%02d\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