Calcula el promedio de los valores contenidos en una matriz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | {-Victor De la Rocha} {-Algoritmia@groups.msn.com} {-www.myalgorithm.com} {PROGRAMA 2: Promedio de los valores contenidos en la matriz} uses crt; type matriz=array[1..100,1..100] of integer; var filas,cols,cont1,cont2,suma,celdas:integer; promedio:real; arreglo:matriz; begin randomize; ClrScr; Write('Filas: ');Readln(filas); Write('Columnas: ');Readln(cols); {ciclo para asignar valores aleatoreamente} suma:=0; for cont1:=1 to filas do begin for cont2:=1 to cols do begin arreglo[cont1,cont2]:=random(10);{asigno valores} writeln('Matriz[',cont1,'][',cont2,']: ',arreglo[cont1,cont2]); {los imprimo en pantalla} suma:=suma+arreglo[cont1,cont2]; end;{for cols} end;{for filas} writeln; celdas:=filas*cols; promedio:=suma/celdas; write('Promedio: ',promedio:0:2); ReadKey;end. |
Filas: 7
Columnas: 3
Matriz[1][1] = 7
Matriz[1][2] = 10
Matriz[1][3] = 8
Matriz[2][1] = 8
Matriz[2][2] = 7
Matriz[2][3] = 7
Matriz[3][1] = 8
Matriz[3][2] = 10
Matriz[3][3] = 9
Matriz[4][1] = 9
Matriz[4][2] = 7
Matriz[4][3] = 8
Matriz[5][1] = 8
Matriz[5][2] = 8
Matriz[5][3] = 7
Matriz[6][1] = 8
Matriz[6][2] = 9
Matriz[6][3] = 9
Matriz[7][1] = 8
Matriz[7][2] = 10
Matriz[7][3] = 8
Promedio: 8.2380952381