Skip to content

Instantly share code, notes, and snippets.

@tuankiet65
Created September 25, 2018 15:35
Show Gist options
  • Save tuankiet65/1d26a694b9b1201549e2e8f88a7092cd to your computer and use it in GitHub Desktop.
Save tuankiet65/1d26a694b9b1201549e2e8f88a7092cd to your computer and use it in GitHub Desktop.
#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