forked from MAYANK25402/Hactober-2023-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdigital clock
More file actions
40 lines (32 loc) · 667 Bytes
/
digital clock
File metadata and controls
40 lines (32 loc) · 667 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
void clearScreen() {
printf("\033[H\033[J");
}
int main() {
int hour, minute, second;
hour = minute = second = 0;
while (1) {
clearScreen();
printf("%02d:%02d:%02d ", hour, minute, second);
fflush(stdout);
second++;
if (second == 60) {
minute += 1;
second = 0;
}
if (minute == 60) {
hour += 1;
minute = 0;
}
if (hour == 24) {
hour = 0;
minute = 0;
second = 0;
}
sleep(1);
}
return 0;
}