E com este exercício está concluído o capitulo. Espero que tenham aproveitado. Qualquer comentário ou dica é só mandar.
Abraço,
Fernando
/* 12279.c 20080911 fmc
* Write a program to read two integers with the following significance.
* The first integer value represents a time of day on a 24 hour clock,
* so that 1245 represents quarter to one mid-day, for example.
* The second integer represents a time duration in a similar way, so
* that 345 represents three hours and 45 minutes.
* This duration is to be added to the first time, and the result
* printed out in the same notation, in this case 1630 which is the
* time 3 hours and 45 minutes after 12.45.
* Typical output might be
* Start time is 1415. Duration is 50. End time is 1505.
* There are a few extra marks for spotting.
* Start time is 2300. Duration is 200. End time is 100.
*
* compile: gcc 12278.c -o 12278
*/
#include<stdio.h>
main() {
int inicio,duracao,termino,h_dur,h_start,m_dur,m_start,ter_h,ter_min;
printf("\n\nEntre com o horario de inicio [hhmm]: ");
scanf("%d",&inicio);
printf("\nEntre com a duração [hhmm]: ");
scanf("%d",&duracao);
h_start=inicio/100;
m_start=inicio-(h_start*100);
h_dur=duracao/100;
m_dur=duracao-(h_dur*100);
ter_h=h_start+h_dur;
ter_min=m_start+m_dur;
if (ter_min>59) {
ter_h++;
ter_min=ter_min-60;
}
if (ter_h>23) {
ter_h=ter_h-24;
}
termino=(ter_h*100)+ter_min;
printf("\nInicio %d. Duração %d. Termino %d\n\n",inicio,duracao,termino);
return 0 ;
}