Question: Write a C program that prompts the user to enter the hours, minutes and seconds of a time in the day, t 1 , say,

Write a C program that prompts the user to enter the hours, minutes and seconds of a time in the day, t1, say, hh1, mm1 and ss1, respectively. Then, it prompts the user to enter and for a later time in the day, t2. The program computes the difference between the two time instants and prints the result in the form hh : mm : ss . Assume the value of the hours is entered using the 24- hour notation (rather than 12-hour notation followed by am or pm). For example, if the user enters t2=15 : 43 : 27 and t1=06 : 58 : 49, the program outputs: The time difference t2 t1 is 08 : 44 :38. Hint: Since t2= hh2:mm2:ss2 and t1= hh1:mm1:ss1. The time difference is t2t1=hh:mm:ss where ss = ss2 ss1, mm = mm2 mm1 and hh = hh2 hh1. If ss1 is greater than ss2, the difference is negative. You want to fix that by borrowing one minute from mm2(worth 60 seconds to make ss positive. A similar argument applies when mm1 is larger than mm2.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!