Use C Program and Write a function that takes the times as t

Use C Program and Write a function that takes the times as three integer arguments 9for hours, minutes, and seconds), and returns the number of seconds since the last time the clock \"struck 12\". Use this function to calculate the amount of time in seconds between two times, both of which are within one 12- hour cycle of the clock. Here is a sample input/output dialog:

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

*/

 Use C Program and Write a function that takes the times as three integer arguments 9for hours, minutes, and seconds), and returns the number of seconds since t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site