Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Napisati program na programskom jeziku C koji
- učitava niz znakova sa standardnog ulaza i koji
- predstavlja vreme trajanja telefonskog razgovora
- (garantovan format hh:mm:ss). Učitavanje niza
- znakova treba vršiti dok god se ne unese razgovor koji
- traje 0 sekundi. Nakon toga program treba da
- izračuna i ispiše ukupno trajanje svih telefonskih
- razgovora po istom ulaznom formatu.
- Primer ulaza: Primer izlaza:
- • 00:42:39 2:32:57
- • 00:35:56
- • 00:22:31
- • 00:51:51
- • 00:00:00
- */
- #include <stdio.h>
- #include <stdlib.h>
- int main(void) {
- char str[9]; //hh:mm:ss
- int hh, mm, ss;
- int totH = 0, totM = 0, totS = 0;
- do {
- scanf("%s", str);
- hh = atoi(str);
- mm = atoi(str+3);
- ss = atoi(str+6);
- totH += hh;
- totM += mm;
- totS += ss;
- } while(hh || mm || ss);
- totM += totS / 60;
- totS %= 60;
- totH += totM / 60;
- totM %= 60;
- printf("%d:%02d:%02d", totH, totM, totS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement