luishenriique

TAP - Caminhoes

Feb 13th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4.     int i = 0, opt, num_cam, cam_carregado = 0;
  5.     float intervalo[11] = {0.0}, t_total = 0.0, media_intervalo = 0.0;
  6.  
  7.     printf("Informe o numero de caminhoes (maximo 10): ");
  8.     scanf("%d", &num_cam); fflush(stdin);
  9.     if(num_cam > 10){
  10.         return main();
  11.     }
  12.  
  13.     printf("\n\n");
  14.     while(i < num_cam){
  15.         do{
  16.             printf("Informe o tempo de saida do caminhao %d: ", i+1);
  17.             scanf("%f", &intervalo[i+1]); fflush(stdin);
  18.         }while(intervalo[i+1] <= intervalo[i]);
  19.  
  20.         t_total += intervalo[i+1] - intervalo[i];
  21.  
  22.         printf("Carga total? (1: Sim - 0: Nao): ");
  23.         scanf("%d", &opt); fflush(stdin);
  24.         if(opt == 1){
  25.             cam_carregado++;
  26.         }
  27.  
  28.         printf("\n");
  29.         i++;
  30.     }
  31.  
  32.     media_intervalo = t_total / (num_cam - 1);
  33.     printf("Media de intervalo: %.2f minutos.\n", media_intervalo);
  34.     printf("Sairam %d caminhoes carregados.\n", cam_carregado);
  35.  
  36.     printf("\n");
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment