Advertisement
Lagx

Cuestionario Programación #5 Módulo 3- Funciones y Registros

Oct 15th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.13 KB | None | 0 0
  1. 2)
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. struct region {
  6.         char nombre[50];
  7.         int numero;
  8.         int votos[6];
  9. };
  10.  
  11. struct candidato {
  12.         char nombre[50];
  13.         int votos;
  14. };
  15.  
  16. struct elecciones {
  17.         struct region regiones[15];
  18.         struct candidato candidatos[6];
  19.         int poblacionChilena;
  20. };
  21.  
  22. unsigned long long percent(unsigned long long);
  23.  
  24. //PROGRAMA PRINCIPAL
  25. int main(void)
  26. {
  27.     char *candidatosChile[6] = {"Sebastian Pinera", "Beatriz Sanchez", "Alejandro Guillier", "MEO", "Carolina Goic", "Alejandro Navarro"};
  28.     struct elecciones elec;
  29.     struct elecciones elec_aux;
  30.     int i,j;
  31.     unsigned long long porcentaje,aux,suma=0;
  32.     scanf("%d",&elec.poblacionChilena);
  33.    
  34.     for(j=0;j<6;j++)
  35.     {
  36.         elec.candidatos[j].votos= 0;
  37.     }
  38.     for(i=0;i<15;i++)
  39.     {
  40.         for(j=0;j<6;j++)
  41.         {
  42.             scanf("%llu",&aux);
  43.             suma = suma+aux;
  44.             elec.candidatos[j].votos=elec.candidatos[j].votos + aux;
  45.         }
  46.     }
  47.     for(i=0;i<6;i++)
  48.     {
  49.         strcpy(elec.candidatos[i].nombre,candidatosChile[i]);
  50.     }
  51.    
  52.     printf("Con un total de %llu votos, ",suma);
  53.    
  54.     for(i=0;i<6;i++)
  55.     {
  56.         for(j=0;j<6;j++)
  57.         {
  58.             if(elec.candidatos[j].votos < elec.candidatos[j+1].votos)
  59.             {
  60.                 elec_aux.candidatos[j]=elec.candidatos[j];
  61.                 elec.candidatos[j]=elec.candidatos[j+1];
  62.                 elec.candidatos[j+1]=elec_aux.candidatos[j];
  63.             }
  64.         }
  65.     }
  66.    
  67.     porcentaje = percent(suma);
  68.     if(elec.candidatos[0].votos > porcentaje)
  69.     {
  70.         printf("se declara Presidente a: %s con %d votos.",elec.candidatos[0].nombre,elec.candidatos[0].votos);
  71.     }
  72.     else
  73.     {
  74.         printf("se declara segunda vuelta entre: %s y %s con %d y %d votos respectivamente.",elec.candidatos[0].nombre,elec.candidatos[1].nombre,elec.candidatos[0].votos,elec.candidatos[1].votos);
  75.     }
  76.    
  77.     return 0;
  78. }
  79. unsigned long long percent(unsigned long long suma)
  80. {
  81.     unsigned long long porcentaje;
  82.     porcentaje = (51*suma)/100;
  83.     return porcentaje;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement