Advertisement
clari-g

junio-ej3

Jul 15th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. main(){
  4.        FILE* fichero;
  5.        fichero=fopen("historial.txt", "a+t");
  6.  
  7. int edad;
  8. int menores = 0;
  9. int mayores = 0;
  10. int personas = 0;
  11. int etotal = 0;
  12. int dia, mes, anio;
  13. float epromedio;
  14.  
  15. printf("Ingrese dia: ");
  16. scanf("%i", &dia);
  17. printf("Ingrese mes: ");
  18. scanf("%i", &mes);
  19. printf("Ingrese anio: ");
  20. scanf("%i", &anio);
  21.  
  22. do{
  23.     printf("\n Ingrese una edad: ");
  24.     scanf("%i", &edad);
  25.    
  26.     if(edad < 18 && edad > 0){
  27.          etotal += edad;
  28.          personas++;
  29.          menores++;
  30.          printf("Es menor. Hay %i menor/es y %i mayor/es.\n", menores, mayores);
  31.     }else if(edad >= 18){
  32.          etotal += edad;
  33.          personas++;
  34.          mayores++;
  35.          printf("Es mayor. Hay %i menor/es y %i mayor/es.\n", menores, mayores);
  36.     }
  37.    
  38. }while(edad != 0);
  39.  
  40. epromedio = etotal/personas;
  41. fprintf(fichero, "\nFecha: %i-%i-%i. Cant total personas: %i. Cantidad mayores: %i. Cantidad menores: %i. Edad promedio %.2f", dia,mes,anio,personas, mayores,menores, epromedio);
  42. fclose(fichero);
  43. getch();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement