Dev - C++ - Mayor y Menor en una matriz

 
Vista:

Mayor y Menor en una matriz

Publicado por Carlos Miguel (1 intervención) el 27/09/2021 10:36:16
Buen día amigos,
Alguien quien me pueda ayudar indicandome mi error, tengo el siguiente código que lo que hace es solicitar datos de una matriz luego los suma y saca el promedio, luego de eso imprime el numero mayor de la matriz y el menor, con este ultimo es con el que tengo problema ya que se salta la línea, gracias por el apoyo.

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
 
using namespace std;
int f = 0, //fila
	c = 0; //columna
int matrizcompleta = 0;
 
int maximo(int matrizcompleta)
{
	int suma = 0;
	int promedio = 0;
 
	cout << "INGRESE EL NUMERO DE FILAS" << endl;
	cin >> f;
	cout << "INGRESE EL NUMERO DE COLUMNAS" << endl;
	cin >> c;
 
	promedio = f * c;
 
	int matriz[100][200];
	int menor = matriz[0][0];
	int mayor = matriz[0][0];
 
	for (int i = 0; i < f; i++)
	{
		for (int j = 0; j < c; j++)
		{
			cout << "Digite un numero [" << i << "][" << j << "]: ";
			cin >> matriz[i][j];
			suma = suma + matriz[i][j];
			// Recorrer la matriz y comparar
			for (int i = 0; i < f; i++) {
				for (int j = 0; j < c; j++) {
					int elementoActual = matriz[i][j];
					if (elementoActual > mayor) mayor = elementoActual;
					if (elementoActual < menor) menor = elementoActual;
				}
			}
		}
	}
	// impresion de matriz
	cout << "\nMatriz Normal\n";
	for (int i = 0; i < f; i++)
	{
		for (int j = 0; j < c; j++)
		{
			cout << matriz[i][j] << " ";
		}
		cout << endl;
	}
 
	cout << "La suma de la matriz es: " << endl;
	cout << suma << endl;
	cout << "El promedio de la matriz es: " << endl;
	cout << suma / promedio << endl;
	printf("Mayor: %d\n", mayor);
	printf("Menor: %d\n", menor);
	return 0;
 
}
int main()
{
	cout << maximo(matrizcompleta) << endl;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder