Question
Difference in Times DXC Automata Fix Questions AMCAT
int difference_in_times(Time *time1,Time * time2)
{
//write code
//5 hrs 30 mins 47 secs //5*60*60 + 30*60 +47
}
-----------------------------------------
solution:
int difference_in_times(Time* time1,Time* time2)
{
int t1s=time1->hour*60*60+time1->minute*60+time1->second;
int t2s=time2->hour*60*60+time2->minute*60+time2->second;
if(Time_compareTo(time1,time2)==1) return t1s-t2s;
else if(Time_compareTo(time1,time2)==-1) return t2s-t1s;
return 0;
}