Computer Science, asked by anupam4219, 9 months ago

Difference Between Two Time Periods Write a program to calculate difference between two time periods

Answers

Answered by Balarakshan
0
Calculate Difference Between Two Time Periods
struct TIME startTime, stopTime, diff; printf("Enter start time: \n"); printf("Enter hours, minutes and seconds respectively: "); scanf("%d %d %d", &startTime.
Pleasemark me brainliest
Answered by aarohi47
1

#include <iostream>

int main()

{

 int hour1, minute1, second1;

 int hour2, minute2, second2;

 int diff_hour, diff_minute, diff_second;

 

 std::cin >> hour1 >> minute1 >> second1;

 std::cin >> hour2 >> minute2 >> second2;

 

 if(second2 > second1)

 {

   minute1--;

   second1 += 60;

 }

 

 diff_second = second1 - second2;

 if(minute2 > minute1)

 {

   hour1--;

   minute1 += 60;

 }

 diff_minute = minute1 - minute2;

 diff_hour = hour1 - hour2;

 std::cout <<diff_hour <<":"<< diff_minute <<":"<<diff_second;

return 0;

}

All test cases are passed .

Similar questions