Skip to content

Instantly share code, notes, and snippets.

@ychoi-kr
Last active May 19, 2021 04:21
Show Gist options
  • Save ychoi-kr/311bc177a9d3fcff0de59f6f3620df84 to your computer and use it in GitHub Desktop.
Save ychoi-kr/311bc177a9d3fcff0de59f6f3620df84 to your computer and use it in GitHub Desktop.
time conversion for digital clock
#include <stdio.h>
#include <stdbool.h>
int main() {
//bool hours12 = false;
bool hours12 = true;
int hour, minute;
scanf("%d%d", &hour, &minute);
int currentTime = hour * 100 + minute;
if (hours12) {
if (currentTime > 1259) {
//printf("%d\n", currentTime - 1200);
printf("%02d:%02d\n", hour - 12, minute);
} else {
//printf("%d\n", currentTime);
printf("%02d:%02d\n", hour, minute);
}
} else {
//printf("%d\n", currentTime);
printf("%02d:%02d\n", hour, minute);
}
return 0;
}
$ gcc clock.c
$ ./a.out
14 04
02:04