/* timestamp.c */ /* the sum of the timestamps */ /* author: Weiwei Chen */ /* date: Oct. 5. 2010 */ #include int main(void) { int s1 = 0, m1 = 0, h1 = 0; /*timestamp1, sec, min, hr */ int s2 = 0, m2 = 0, h2 = 0; /*timestamp2, sec, min, hr */ int s = 0, m = 0, h = 0; /*timestamp, sec, min, hr */ int tmp1 = 0, tmp2 = 0; /*temporary variables */ int sum = 0; /*sum of the timestamps in seconds */ printf("Please enter two timestamp values s1, m1, h1, s2, m2, h2 \n"); printf("s1: "); scanf("%d", &s1); printf("m1: "); scanf("%d", &m1); printf("h1: "); scanf("%d", &h1); printf("Timestamp 1 is %d seconds, %d minutes, %d hours. \n", s1, m1, h1); printf("s2: "); scanf("%d", &s2); printf("m2: "); scanf("%d", &m2); printf("h2: "); scanf("%d", &h2); printf("Timestamp 2 is %d seconds, %d minutes, %d hours. \n", s2, m2, h2); tmp1 = h1 * 60 * 60 + m1 * 60 + s1; tmp2 = h2 * 60 * 60 + m2 * 60 + s2; sum = tmp1 + tmp2; s = sum % 60; sum = sum / 60; m = sum % 60; sum = sum / 60; h = sum; printf("The sum of the timestamp is %d seconds, %d minutes, %d hours. \n", s, m, h); return 0; }