Last active
May 19, 2021 04:21
-
-
Save ychoi-kr/311bc177a9d3fcff0de59f6f3620df84 to your computer and use it in GitHub Desktop.
time conversion for digital clock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gcc clock.c | |
$ ./a.out | |
14 04 | |
02:04 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.facebook.com/groups/easyarduino/permalink/2846844918898849/?__cft__[0]=AZVYaAhlqoThUsWglEJ6hnes_Hw74SB8F2r9c6QZnsMzrw-X0rY1YsPgdEcI4ovH7tNeyjWTEZRaYf4P60a-SnqkbZDDQBeD9h7CrdZqx_dWnBzwOeIa_VQha1HBqKiYwQZVwrl1TyXaGRO8e6i1l-8Ddg3VVUWaGzWKn3TsmVxsl_Sk6zqjjJGMBdD5owfcfvk&__tn__=%2CO%2CP-R