Curso de Programación en C/Prog62
								
								Ir a la navegación
				Ir a la búsqueda
				
					
								
							
		Prog62
 1 #include <stdio.h>
 2 
 3 #define MESES 12    // number of mess in a ano
 4 #define ANOS   5    // number of anos of data
 5 
 6 int main( void )
 7 {
 8   // init Lluvia para 2000 - 2004
 9   const float lluvia[ANOS][MESES] =
10   {
11     {4.3,4.3,4.3,3.0,2.0,1.2,0.2,0.2,0.4,2.4,3.5,6.6},
12     {8.5,8.2,1.2,1.6,2.4,0.0,5.2,0.9,0.3,0.9,1.4,7.3},
13     {9.1,8.5,6.7,4.3,2.1,0.8,0.2,0.2,1.1,2.3,6.1,8.4},
14     {7.2,9.9,8.4,3.3,1.2,0.8,0.4,0.0,0.6,1.7,4.3,6.2},
15     {7.6,5.6,3.8,2.8,3.8,0.2,0.0,0.0,0.0,1.3,2.6,5.2}
16   };
17 
18   int   ano,
19         mes;
20   float subtot,
21         total;
22 
23   puts( " AÑO     LLUVIA  (pulgadas)" );
24   for ( ano = 0, total = 0; ano < ANOS; ano++ )
25   {
26     for (mes = 0, subtot = 0; mes < MESES; mes++)
27       subtot += lluvia[ano][mes];
28     printf( "%5d %15.1f\n", 2000 + ano, subtot );
29     total += subtot; 
30   }
31   printf( "\nEl promedio es %.1f pulgadas.\n\n", total/ANOS );
32   printf( "Promedios Mensuales:\n\n" );
33   printf( " Ene  Feb  Mar  Abr  May  Jun  Jul  Ago  Sep  Oct "
34           " Nov  Dec\n" );
35 
36   for( mes = 0; mes < MESES; mes++ )
37   {
38     for( ano = 0, subtot =0; ano < ANOS; ano++ )
39       subtot += lluvia[ano][mes];
40     printf( "%4.1f ", subtot/ANOS );
41   }
42   puts( "" );
43 
44   return 0;
45 }
Resultado
[rrc@Pridd CClase]$ gcc -Wall -O2 -oProg62 Prog62.c [rrc@Pridd CClase]$ ./Prog62 AÑO LLUVIA (pulgadas) 2000 32.4 2001 37.9 2002 49.8 2003 44.0 2004 32.9 El promedio es 39.4 pulgadas. Promedios Mensuales: Ene Feb Mar Abr May Jun Jul Ago Sep Oct Nov Dec 7.3 7.3 4.9 3.0 2.3 0.6 1.2 0.3 0.5 1.7 3.6 6.7 [rrc@Pridd CClase]$