Advertisement
KvArt

Sabiranje vremena svih tel. poziva

Jul 10th, 2022
986
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. /*Napisati program na programskom jeziku C koji
  2. učitava niz znakova sa standardnog ulaza i koji
  3. predstavlja vreme trajanja telefonskog razgovora
  4. (garantovan format hh:mm:ss). Učitavanje niza
  5. znakova treba vršiti dok god se ne unese razgovor koji
  6. traje 0 sekundi. Nakon toga program treba da
  7. izračuna i ispiše ukupno trajanje svih telefonskih
  8. razgovora po istom ulaznom formatu.
  9.  
  10. Primer ulaza:  Primer izlaza:
  11. • 00:42:39     2:32:57
  12. • 00:35:56
  13. • 00:22:31
  14. • 00:51:51
  15. • 00:00:00
  16. */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. int main(void) {
  21. char str[9]; //hh:mm:ss
  22. int hh, mm, ss;
  23. int totH = 0, totM = 0, totS = 0;
  24. do {
  25. scanf("%s", str);
  26. hh = atoi(str);
  27. mm = atoi(str+3);
  28. ss = atoi(str+6);
  29. totH += hh;
  30. totM += mm;
  31. totS += ss;
  32. } while(hh || mm || ss);
  33. totM += totS / 60;
  34. totS %= 60;
  35. totH += totM / 60;
  36. totM %= 60;
  37. printf("%d:%02d:%02d", totH, totM, totS);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement