bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / practice-c / pc017.c

pc017.c (913B)


      1 /* Write a program to calculate the difference between two time periods using structures. */
      2 
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 
      6 typedef struct time_reference
      7 {
      8     int hour;
      9     int min;
     10     int sec;
     11 } timeRef;
     12 
     13 int main()
     14 {
     15     timeRef a, b;
     16     long long int tSeconds_a, tSeconds_b, timeDiff;
     17 
     18     printf("== Note: Time should be entered in HH-MM-SS 24-hour clock format ==");
     19     printf("\nEnter the time reference a: ");
     20     scanf("%d-%d-%d", &a.hour, &a.min, &a.sec);
     21     printf("Enter the time reference b: ");
     22     scanf("%d-%d-%d", &b.hour, &b.min, &b.sec);
     23 
     24     tSeconds_a = (a.hour * 3600) + (a.min * 60) + a.sec;
     25     tSeconds_b = (b.hour * 3600) + (b.min * 60) + b.sec;
     26 
     27     timeDiff = tSeconds_a - tSeconds_b;
     28     timeDiff = abs(timeDiff);
     29 
     30     printf("\nTime Difference: %lld Hours, %lld Minutes, %lld Seconds.", timeDiff / 3600, (timeDiff % 3600) / 60, (timeDiff % 3600) % 60);
     31     return 0;
     32 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror