assignment-s-24.c (1071B)
1 /* 2 * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 18 Jan 2026 3 * Repo: https://github.com/notamitgamer/bsc 4 * License: MIT 5 */ 6 7 /* Write a program to calculate the difference between two time periods using structures. */ 8 9 #include <stdio.h> 10 #include <stdlib.h> 11 12 struct time_dif 13 { 14 int hour; 15 int min; 16 int sec; 17 }; 18 19 int main() 20 { 21 struct time_dif tpA, tpB; 22 long int tfA, tfB, tdif; 23 printf("Enter the start time in this 24 hours clock format (HH MM SS): "); 24 scanf("%d %d %d", &tpA.hour, &tpA.min, &tpA.sec); 25 printf("Enter the end time in this 24 hours clock format (HH MM SS): "); 26 scanf("%d %d %d", &tpB.hour, &tpB.min, &tpB.sec); 27 28 tfA = tpA.hour * 3600 + tpA.min * 60 + tpA.sec; 29 tfB = tpB.hour * 3600 + tpB.min * 60 + tpB.sec; 30 tdif = tfB - tfA; 31 if (tdif < 0) 32 { 33 printf("\nWrong information, End time should be later than Start time."); 34 return 1; 35 } 36 printf("\nTime difference: %ld Hour(s) %ld Minutes(s) %ld Second(s).", tdif / 3600, (tdif % 3600) / 60, (tdif % 3600) % 60); 37 38 return 0; 39 }