Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  aaa
Language: C/C++
Code:
#include <stdio.h>
#include <time.h>
int main()
{
  //DEFINIR VARIABLES Y MATRICES
 // int votos[5][4]={294,64,213,65,178,32,423,17,246,79,165,21,542,65,975,34,850,64,1002,23}, f,c;
int votos[6][4]={294,64,213,65,178,32,423,17,246,79,165,21,542,65,975,34,850,64,1002,23}, f,c,op, sv=0,sc=0;  
srand(time(NULL));

  printf("t********************************************** n");
  printf("tPROGRAMA DE VOTACIOES DE 5 ZONAS 4 CANDIDATOS n");
  printf("t********************************************** nn");
  
  //LEER LOS DATOS DE LA MATRIZ
  /*for(f=0; f<5; f=f+1){
           for(c=0;c<4;c=c+1){
                    //scanf("%i",&votos[f][c]);          
                    votos[f][c]=rand()%1002;
                              }
           }*/
           
           do{
                  printf("1. Imprimir los resultados en forma de tabla.n");
                  printf("2. Calcular el total de votos n");
                  printf("3. Calcular el total de votos por candidato.n");
                  printf("4. Calcular el porcentaje de votos del total por candidato.n");
                  printf("5.Calcule el total de votos por zona.n");
                  printf("6.Imprima el candidato ganador.n");
                  printf("7.Si ningun candidato recibe mas del 50%, de la votacion, imprimir los dos candidatos de mayor votacion que pasarian a la segunda vuelta. n");           
                  printf("8.Salir.n");
                  printf("INGRESE LA OPCION  .n");
                  scanf("%i",&op);
                  switch(op){
                             case 1 :                
                                  //imprimir las votaciones
                                    for(f=0; f<5; f=f+1){
                                               for(c=0;c<4;c=c+1){
                                                                   printf("%it",votos[f][c]);          
                                                                   }
                                                                                   printf("n");
                                                                                   }
                             break;
                             case 2 :                
                                  //imprimir las votaciones
                                    for(f=0; f<5; f=f+1){
                                               for(c=0;c<4;c=c+1){
                                                                  sv=votos[f][c]+sv;          
                                                                   }
                                                                                  
                                                                                   }
                                    printf("LA SUMA DE LOS VOTOS ES %inn n", sv);
                             break;
                              case 3 :                
                                  //imprimir las votaciones
                                    for(c=0; c<4; c=c+1){
                                               for(f=0;f<5;f=f+1){
                                                                  sc=sc+votos[f][c];
                                                                           
                                                                   }
                                                                   votos[5][c]=sc;  
                                                                   sc=0;                                                                                 sc=0;
                                                                                  
                                                                   }
                                                                    //imprimir la suma de votaciones por cadidato
                                      for(f=0; f<6; f=f+1){
                                               for(c=0;c<4;c=c+1){
                                                                  printf("%i t",votos[f][c]);
                                                                           
                                                                    }
                                                                 printf("n") ;                                                                        sc=0;
                                                                                  
                                                                   }
                                    
                             break;
                               case 5 :
                               //
                               for(c=0; c<4; c=c+1){
                              for(l=0;l<5;l=l+1){
                                        sc=sc+votos[l][c];           
                                                                   }
                                                                   votos[5][c]=sc;  
                                                                   sc=0;                                                                                 sc=0;
                                                                                  
                                                                   }
                                             
                              for(c=0; c<4; c=c+1){
                                       votos[6][c]=votos[5][c]/5352*100;
                       
                                       
                                       }                  
                                      for(l=0; l<7; l=l+1){
                                               for(c=0;c<4;c=c+1){
                                                                  printf("%i t",votos[l][c]);
                                                                           
                                                                    }
                                                                 printf("n") ;                                                                        sc=0;
                                                                                  
                                                                   }
                                                                     
                                                                   break;
                                              
                                                                                   
                                                                                   
                                                                                   }
           }while(op!=8);
  system("PAUSE");     
  return 0;
}
     
          
Comments: