fork download
  1. #include <stdio.h>
  2.  
  3. struct time1 {
  4. int seconds1;
  5. int minutes1;
  6. int hours1;
  7. };
  8.  
  9. struct time2 {
  10. int seconds2;
  11. int minutes2;
  12. int hours2;
  13. };
  14.  
  15. void timeDif(struct time1 t1, struct time2 t2) {
  16.  
  17. int secDif = t2.seconds2 - t1.seconds1;
  18. int minDif = t2.minutes2 - t1.minutes1;
  19. int hourDif = t2.hours2 - t1.hours1;
  20.  
  21. printf("The difference is %d:%d:%d\n", hourDif, minDif, secDif);
  22. }
  23.  
  24.  
  25.  
  26. int main(void) {
  27. struct time1 t1; struct time2 t2;
  28. printf("Enter seconds1 (ss)\n");
  29. scanf("%d", &t1.seconds1);
  30.  
  31. printf("Enter minutes1 (mm)\n");
  32. scanf("%d", &t1.minutes1);
  33.  
  34. printf("Enter hours1 (hh)\n");
  35. scanf("%d", &t1.hours1);
  36.  
  37. printf("Enter seconds2 (ss)\n");
  38. scanf("%d", &t2.seconds2);
  39.  
  40. printf("Enter minutes2 (mm)\n");
  41. scanf("%d", &t2.minutes2);
  42.  
  43. printf("Enter hours2 (hh)\n");
  44. scanf("%d", &t2.hours2);
  45.  
  46. timeDif(t1, t2);
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 2012KB
stdin
3
4
5
6
7
8
stdout
Enter seconds1 (ss)
Enter minutes1 (mm)
Enter hours1 (hh)
Enter seconds2 (ss)
Enter minutes2 (mm)
Enter hours2 (hh)
The difference is 3:3:3