Use C Program and Write a function that takes the times as t
Solution
//C code time difference in seconds
#include <stdio.h>
#include <string.h>
int main()
{
int hour1, minute1, second1;
int hour2, minute2, second2;
printf(\"Enter the first time as three integers: \");
scanf(\"%d%d%d\",&hour1,&minute1,&second1);
printf(\"Enter the second time as three integers: \");
scanf(\"%d%d%d\",&hour2,&minute2,&second2);
int seconds = (hour2-(hour1+1))*60*60;
if(seconds < 0)
{
printf(\"Invalid Input\ \");
return 0;
}
seconds = seconds + (60-minute1)*60 - second1;
if(seconds < 0)
{
printf(\"Invalid Input\ \");
return 0;
}
seconds = seconds + (minute2)*60 + second2;
printf(\"The difference between the time is %d seconds\ \", seconds);
return 0;
}
/*
output:
Enter the first time as three integers: 4 23 1
Enter the second time as three integers: 3 54 1
Invalid Input
Enter the first time as three integers: 3 12 20
Enter the second time as three integers: 4 25 30
The difference between the time is 4390 seconds
*/
