-
-
Save tuankiet65/1d26a694b9b1201549e2e8f88a7092cd to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
int h, m, s, n; | |
int total_s; | |
int to_timestamp(int h, int m, int s) { | |
return (h * (60 * 60)) + (m * 60) + s; | |
} | |
void to_hms_tuple(int timestamp, int *h, int *m, int *s) { | |
*h = timestamp / (60*60); | |
timestamp %= (60 * 60); | |
*m = timestamp / 60; | |
timestamp %= 60; | |
*s = timestamp; | |
} | |
int main() { | |
printf("Enter hour: "); | |
scanf("%d", &h); | |
printf("Enter minute: "); | |
scanf("%d", &m); | |
printf("Enter second: "); | |
scanf("%d", &s); | |
printf("Enter n: "); | |
scanf("%d", &n); | |
int new_h, new_m, new_s; | |
int new_timestamp = to_timestamp(h, m, s) + n; | |
to_hms_tuple(new_timestamp, &new_h, &new_m, &new_s); | |
printf("New date is %dh, %dm, %ds\n", new_h, new_m, new_s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment