TheMalva

Ejercicio tipo parcial 1

Oct 6th, 2017
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.62 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. //Definición de funciones
  4. void cargar (int [4][3]);
  5. int total_trim (int [4][3]);
  6. void total_edad (int [4][3]);
  7. void total_mes (int [4][3]);
  8. int mes_mayor (int [4][3]);
  9.  
  10. int main()
  11. {
  12.     int matriz[4][3]={0};
  13.     int total_trimestre, mayor;
  14.  
  15.     cargar(matriz);
  16.     total_trimestre = total_trim(matriz);
  17.     total_edad(matriz);
  18.     total_mes(matriz);
  19.     mayor = mes_mayor(matriz);
  20.  
  21.     printf("El total de enfermos en el trimestre fue de: %d\n\n",total_trimestre);
  22.     printf("El mes con mayor cantidad de enfermos fue el mes: %d\n\n", mayor);
  23.  
  24. }
  25.  
  26. void cargar (int matriz[4][3])
  27. {
  28.     int f, c;
  29.     for(f=0 ; f<4 ; f++)
  30.     {
  31.         if(f==0)
  32.             printf("Ingrese la cantidad de ninnos del mes de \n");
  33.         if(f==1)
  34.             printf("Ingrese la cantidad de jovenes del mes de \n");
  35.         if(f==2)
  36.             printf("Ingrese la cantidad de adultos del mes de \n");
  37.         if(f==3)
  38.             printf("Ingrese la cantidad de ancianos del mes de \n");
  39.  
  40.         for(c=0 ; c<3 ; c++)
  41.         {
  42.             if(c==0)
  43.             {
  44.                 printf("enero: ");
  45.                 scanf("%d",&matriz[f][c]);
  46.             }
  47.  
  48.             if(c==1)
  49.             {
  50.                 printf("febrero: ");
  51.                 scanf("%d",&matriz[f][c]);
  52.             }
  53.  
  54.             if(c==2)
  55.             {
  56.                 printf("marzo: ");
  57.                 scanf("%d",&matriz[f][c]);
  58.             }
  59.  
  60.         }
  61.     }
  62. }
  63.  
  64.  
  65. int total_trim (int matriz[4][3])
  66. {
  67.     int suma_total=0, f, c;
  68.     for(f=0 ; f<4 ; f++)
  69.     {
  70.         for(c=0 ; c<3 ; c++)
  71.         {
  72.             suma_total = suma_total + matriz[f][c];
  73.         }
  74.     }
  75.     return suma_total;
  76. }
  77.  
  78. void total_edad (int matriz[4][3])
  79. {
  80.     int f, c, total=0;
  81.     for(f=0 ; f<4 ; f++)
  82.     {
  83.         total=0;
  84.         for(c=0 ; c<3 ; c++)
  85.         {
  86.             total = total + matriz[f][c];
  87.         }
  88.         printf("El total de (%d) en el trimestre fue de: %d\n\n", f+1, total);
  89.     }
  90. }
  91.  
  92. void total_mes (int matriz[4][3])
  93. {
  94.     int f, c, total=0;
  95.     for(c=0 ; c<3 ; c++)
  96.     {
  97.         total=0;
  98.         for(f=0 ; f<4 ; f++)
  99.         {
  100.             total = total + matriz[f][c];
  101.         }
  102.         printf("El total de enfermos en el mes %d fue de: %d\n\n", c+1, total);
  103.     }
  104. }
  105.  
  106.  
  107. int mes_mayor (int matriz[4][3])
  108. {
  109.     int f, c, suma, mayor=0, mes=0;
  110.  
  111.     for(c=0 ; c<3 ; c++)
  112.     {
  113.         suma=0;
  114.         for(f=0 ; f<4 ; f++)
  115.         {
  116.             suma=suma+matriz[f][c];
  117.         }
  118.         if(suma > mayor)
  119.         {
  120.             mes = c+1;
  121.             mayor = suma;
  122.         }
  123.     }
  124.     return mes;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment