Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2)
- #include <stdio.h>
- #include <string.h>
- struct region {
- char nombre[50];
- int numero;
- int votos[6];
- };
- struct candidato {
- char nombre[50];
- int votos;
- };
- struct elecciones {
- struct region regiones[15];
- struct candidato candidatos[6];
- int poblacionChilena;
- };
- unsigned long long percent(unsigned long long);
- //PROGRAMA PRINCIPAL
- int main(void)
- {
- char *candidatosChile[6] = {"Sebastian Pinera", "Beatriz Sanchez", "Alejandro Guillier", "MEO", "Carolina Goic", "Alejandro Navarro"};
- struct elecciones elec;
- struct elecciones elec_aux;
- int i,j;
- unsigned long long porcentaje,aux,suma=0;
- scanf("%d",&elec.poblacionChilena);
- for(j=0;j<6;j++)
- {
- elec.candidatos[j].votos= 0;
- }
- for(i=0;i<15;i++)
- {
- for(j=0;j<6;j++)
- {
- scanf("%llu",&aux);
- suma = suma+aux;
- elec.candidatos[j].votos=elec.candidatos[j].votos + aux;
- }
- }
- for(i=0;i<6;i++)
- {
- strcpy(elec.candidatos[i].nombre,candidatosChile[i]);
- }
- printf("Con un total de %llu votos, ",suma);
- for(i=0;i<6;i++)
- {
- for(j=0;j<6;j++)
- {
- if(elec.candidatos[j].votos < elec.candidatos[j+1].votos)
- {
- elec_aux.candidatos[j]=elec.candidatos[j];
- elec.candidatos[j]=elec.candidatos[j+1];
- elec.candidatos[j+1]=elec_aux.candidatos[j];
- }
- }
- }
- porcentaje = percent(suma);
- if(elec.candidatos[0].votos > porcentaje)
- {
- printf("se declara Presidente a: %s con %d votos.",elec.candidatos[0].nombre,elec.candidatos[0].votos);
- }
- else
- {
- 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);
- }
- return 0;
- }
- unsigned long long percent(unsigned long long suma)
- {
- unsigned long long porcentaje;
- porcentaje = (51*suma)/100;
- return porcentaje;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement