#include <stdio.h>
struct time
{
int seconds;
int minutes;
int hours;
};
void differenceBetweentimePeriod(struct time t1, struct time t2, struct time *diff);
int main()
{
struct time starttime, stoptime, diff;
printf("Enter start time: \n");
printf("Enter hours, minutes and seconds respectively: ");
scanf("%d %d %d", &starttime.hours, &starttime.minutes, &starttime.seconds);
printf("Enter stop time: \n");
printf("Enter hours, minutes and seconds respectively: ");
scanf("%d %d %d", &stoptime.hours, &stoptime.minutes, &stoptime.seconds);
// Calculate the difference between the start and stop time period.
differenceBetweentimePeriod(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 differenceBetweentimePeriod(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;
}
struct time
{
int seconds;
int minutes;
int hours;
};
void differenceBetweentimePeriod(struct time t1, struct time t2, struct time *diff);
int main()
{
struct time starttime, stoptime, diff;
printf("Enter start time: \n");
printf("Enter hours, minutes and seconds respectively: ");
scanf("%d %d %d", &starttime.hours, &starttime.minutes, &starttime.seconds);
printf("Enter stop time: \n");
printf("Enter hours, minutes and seconds respectively: ");
scanf("%d %d %d", &stoptime.hours, &stoptime.minutes, &stoptime.seconds);
// Calculate the difference between the start and stop time period.
differenceBetweentimePeriod(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 differenceBetweentimePeriod(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;
}