devC and requires only include and Write a C program that re
(devC++) and requires only #include <stdio.h> and <math.h>
Write a C program that reads two timeslots formatted as hh:mm:ss. The program should calculate the time difference between two input timeslots. Print the results as the following format: Output example: Enter time 1: 09:37:41 Enter time 2:15:18:84 Time 1 Time 2 Time Difference 09:37:41 15:18:84 05:34:43Solution
// C code determine time difference
#include <stdio.h>
#include <math.h>
int main()
{
int hour1,minute1,second1;
int hour2,minute2,second2;
int hour, minute, second;
printf(\"Enter time 1: \");
scanf(\"%d:%d:%d\",&hour1,&minute1,&second1);
printf(\"Enter time 2: \");
scanf(\"%d:%d:%d\",&hour2,&minute2,&second2);
printf(\"%10s%10s%20s\ \",\"Time1\",\"Time2\",\"Time Difference\");
printf(\"--------------------------------------------\ \");
printf(\" %d:%d:%d %d:%d:%d\\t\",hour1,minute1,second1,hour2,minute2,second2);
if(hour1 > hour2)
{
if(second2 > second1)
{
--minute1;
second1 += 60;
}
second = second1 - second2;
if(minute2 > minute1)
{
--hour1;
minute1 += 60;
}
minute = minute1 - minute2;
hour = hour1 - hour2;
}
else
{
int t = hour1;
hour1 = hour2;
hour2 = t;
t = second1;
second1 = second2;
second2 = t;
t = minute1;
minute1 = minute2;
minute2 = t;
if(second2 > second1)
{
--minute1;
second1 += 60;
}
second = second1 - second2;
if(minute2 > minute1)
{
--hour1;
minute1 += 60;
}
minute = minute1 - minute2;
hour = hour1 - hour2;
}
printf(\" %d:%d:%d\ \",hour,minute,second );
}
/*
output:
Enter time 1: 15:12:24
Enter time 2: 09:37:41
Time1 Time2 Time Difference
--------------------------------------------
15:12:24 9:37:41 5:34:43
*/

