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
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


0