Dev - C++ - Programa que me diga si en una matriz hay alguna fila con los mimos valores

 
Vista:

Programa que me diga si en una matriz hay alguna fila con los mimos valores

Publicado por Pepe (1 intervención) el 05/01/2020 16:42:26
Hola,

Debo hacer un programa que me diga si en una matriz hay alguna fila donde todos los valores son zero,

Me podeis ayudar?

Gracias

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
#define FILAS 3
#define COLUMNAS 3
#include <iostream>
#include <cstdlib>
#include <time.h>
 
using namespace std;
 
int main() {
	int i,j,n;
	int matriu [FILAS][COLUMNAS];
	bool nohaycero=false;
 
// LLENAR MATRIZ
 
	// srand (time (NULL));
	for (i=0; i<FILAS;i++)
	{
		for (j=0; j<COLUMNAS;j++)
		{
			cout << "entra valores ";
			cin >> matriu[i][j];
 
		}
	}
// IMPRIMIR LA MATRIZ
 
	for (i=0;i<FILAS;i++)
	{
		for (j=0; j<COLUMNAS;j++)
		{
			cout << matriu [i][j]<<" ";
		}
		cout << endl;
	}
 
	// HACEMOS CONSULTA
 
	for (i=0 ; i<FILAS ; i++)
			{
		for (j=0 ; j<COLUMNAS; j++)
			{
                n=0;
                while (n<COLUMNAS and !nohaycero)
                {nohaycero=false;
                    if (matriu[i][j] == 0)
                        n++;
                    else
                        nohaycero=true;
 
                }
                        j++;
 
                }
                        i++;
			}
 
	if (nohaycero)
	cout << "No hay fila de ceros";
	else
	cout << "Si que hay fila de ceros";
 
 
 
}
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
Imágen de perfil de Alfil
Val: 4.344
Oro
Ha mantenido su posición en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

Programa que me diga si en una matriz hay alguna fila con los mimos valores

Publicado por Alfil (1444 intervenciones) el 05/01/2020 23:47:39
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
#include <iostream>
 
using namespace std;
 
const int sz = 3;
 
void leerMatriz( int m[sz][sz] );
void imprimirMatriz( const int m[sz][sz] );
bool comprobarMatriz( const int m[sz][sz] );
 
int main()
{
    int matriz[sz][sz];
 
    leerMatriz(matriz);
    imprimirMatriz(matriz);
 
    comprobarMatriz(matriz) ? cout << "\nHay filas con ceros" : cout << "\nNo hay filas con ceros";
 
    cout << endl;
 
    return 0;
 
}
 
void leerMatriz( int m[sz][sz] )
{
    cout << "\nIntroducir datos:\n";
    for(int i = 0; i < sz; i++) {
        for(int j = 0; j < sz; j++) {
            cout << "[" << i << "][" << j << "]: ";
            cin >> m[i][j];
        }
    }
}
 
void imprimirMatriz( const int m[sz][sz] )
{
    cout << "\nMatriz:\n";
    for(int i = 0; i < sz; i++) {
        cout << "| ";
        for(int j = 0; j < sz; j++) {
            cout << m[i][j] << " ";
        }
        cout << " |\n";
    }
}
 
bool comprobarMatriz( const int m[sz][sz] )
{
    for(int i = 0; i < sz; i++) {
        int col = 0;
        for(int j = 0; j < sz; j++) {
            if(m[i][j] == 0 ) col++;
        }
        if(col == sz) return true;
    }
 
    return false;
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar