#include #include struct horaire { int heure; int minute; int seconde; }; void afficherHoraire(struct horaire h) { printf("%02d:%02d:%02d", h.heure, h.minute, h.seconde); } int calculerSecondes(struct horaire h) { return h.heure * 3600 + h.minute * 60 + h.seconde; } int comparerHoraires(struct horaire h1, struct horaire h2) { int m1 = calculerSecondes(h1); int m2 = calculerSecondes(h2); if (m1 > m2) { return 1; } if (m1 < m2) { return -1; } return 0; } void ajouterUneSeconde(struct horaire* h) { h->seconde++; if (h->seconde == 60) { h->seconde = 0; h->minute++; if (h->minute == 60) { h->minute = 0; h->heure++; if (h->heure == 24) { h->heure = 0; } } } } void main(void) { struct horaire h1 = { 12, 59,59 }; struct horaire h2 = { 23, 59,59 }; afficherHoraire(h1); printf(" = %d secondes\n", calculerSecondes(h1)); afficherHoraire(h2); printf(" = %d secondes\n", calculerSecondes(h2)); printf("\n"); printf("%d\n", comparerHoraires(h1, h1)); printf("%d\n", comparerHoraires(h1, h2)); printf("%d\n", comparerHoraires(h2, h1)); printf("\n"); ajouterUneSeconde(&h1); afficherHoraire(h1); printf("\n"); ajouterUneSeconde(&h2); afficherHoraire(h2); printf("\n"); }