nikolas_serafini

Simulado - Prova 2 - Questão 03

Jul 7th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include <string.h>
  2. #define PEOPLE 100
  3. #define NAMESIZE 31
  4.  
  5. int main()
  6. {
  7.     int age[PEOPLE],i,flag = 0,oldestId = 0,total = 0;
  8.     float weight[PEOPLE];
  9.     char names[PEOPLE][NAMESIZE];
  10.  
  11.     while (1) {
  12.         printf("Entre com o nome do usuario : (tecle apenas ENTER pra finalizar)\n");
  13.         fflush(stdin);
  14.         gets(names[total]);
  15.         if (names[total][0] == '\0')
  16.             break;
  17.         printf("Entre com a idade:\n");
  18.         scanf("%d",&age[total]);
  19.         printf("Entre com o peso:\n");
  20.         scanf("%f",&weight[total]);
  21.        
  22.         if (age[total] == age[oldestId] && total != i) {
  23.             flag = 1;
  24.         }
  25.         else if (age[total] > age[oldestId]) {
  26.             oldestId = total;
  27.             flag = 0;
  28.         }
  29.         total++;
  30.     }
  31.  
  32.     printf("Pessoas com idade entre 15 e 19 anos e peso superior a 80Kg :\n");
  33.     for (i = 0; i < total; i++) {
  34.         if (age[i] >= 15 && age[i] <= 19 && weight[i] > 80)
  35.             puts(names[i]);
  36.     }
  37.  
  38.     printf("Usuario mais velho :\n");
  39.     if (flag == 1)
  40.         printf("%s\nExiste(m) outro(s).\n",names[oldestId]);
  41.     else
  42.         puts(names[oldestId]);
  43.    
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment