#include <stdio.h>
#include <unistd.h> // for sleep function
int main() {
int h, m, s;
int d = 1; // delay of 1 second
int loop_limit = 100; // limit the loop to 100 iterations
printf("Set time : \n");
scanf("%d%d%d", &h, &m, &s);
if (h > 12 || m >= 60 || s >= 60) {
printf("ERROR ! \n");
return 1;
}
for (int i = 0; i < loop_limit; i++) {
s++;
if (s > 59) {
m++;
s = 0;
}
if (m > 59) {
h++;
m = 0;
}
if (h > 12) {
h = 1;
}
printf("\n Clock :");
printf("\n%02d:%02d:%02d", h, m, s);
fflush(stdout); // flush output to ensure immediate display
sleep(d); // slows down sleep to make it more real
printf("\033[H\033[J"); // clears the screen (for Unix-like systems)
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: