I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
#include <stdio.h> struct Time { int seconds; int minutes; int hours; }; void differenceBetweentwoTimePeriod(struct Time t1, struct Time t2, struct Time *diff); int main() { struct Time startTime, stopTime, diff; printf("Please enter start time: \n"); printf("Enter hours, minutes and seconds respectively: "); scanf("%d %d %d", &startTime.hours, &startTime.minutes, &startTime.seconds); printf("Please enter stop time: \n"); printf("Enter hours, minutes and seconds respectively: "); scanf("%d %d %d", &stopTime.hours, &stopTime.minutes, &stopTime.seconds); // Calculateing the difference differenceBetweentwoTimePeriod(startTime, stopTime, &diff); printf("\nTIME DIFFERENCE: %d:%d:%d - ", startTime.hours, startTime.minutes, startTime.seconds); printf("%d:%d:%d ", stopTime.hours, stopTime.minutes, stopTime.seconds); printf("= %d:%d:%d\n", diff.hours, diff.minutes, diff.seconds); return 0; } void differenceBetweentwoTimePeriod(struct Time start, struct Time stop, struct Time *diff) { if(stop.seconds > start.seconds){ --start.minutes; start.seconds += 60; } diff->seconds = start.seconds - stop.seconds; if(stop.minutes > start.minutes){ --start.hours; start.minutes += 60; } diff->minutes = start.minutes - stop.minutes; diff->hours = start.hours - stop.hours; }
Please enter start time:
Enter hours, minutes and seconds respectively: 8
20
50
Please enter stop time:
Enter hours, minutes and seconds respectively: 6
25
30
TIME DIFFERENCE: 8:20:50 - 6:25:30 = 1:55:20
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
Result:
Please enter start time:
Enter hours, minutes and seconds respectively: 8
20
50
Please enter stop time:
Enter hours, minutes and seconds respectively: 6
25
30
TIME DIFFERENCE: 8:20:50 - 6:25:30 = 1:55:20
need an explanation for this answer? contact us directly to get an explanation for this answer