-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatriz.cpp
More file actions
66 lines (48 loc) · 1.51 KB
/
Copy pathmatriz.cpp
File metadata and controls
66 lines (48 loc) · 1.51 KB
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
/*
Realizar un programa en C++ que el usuario indique el tamaño de una matriz (filas y columnas), llene dicha matriz con valores enteros y adicionalmente el programa debe mostrar:
Los valores múltiplos de 3
El promedio de los valores positivos ubicados en columnas pares
El Mayor valor entre los valores negativos ingresados a la matriz.
*/
#include <iostream>
using namespace std;
int main (){
int filas,columnas;
cout<<"ingrese el numero de filas"<<endl;
cin>>filas;
cout<<"ingrese el numero de columnas"<<endl;
cin>>columnas;
int matriz[filas][columnas];
int suma=0,cant=0;
int multiplos[filas*columnas],indice=0;
int mayorN=0;
for (int x=0;x<filas;x++){
for(int y=0;y<columnas;y++){
cout<<"ingrese el valor de la fila: "<<x<<" y columna: "<<y<<endl;
cin>>matriz[x][y];
}
}
for (int x=0;x<filas;x++){
for(int y=0;y<columnas;y++){
cout<<matriz[x][y];
if(matriz[x][y]%3==0){
multiplos[indice]=matriz[x][y];
indice++;
}
if(x%2!=0 && matriz[x][y]%2!=0){
cant++;
suma+=matriz[x][y];
}
if((matriz[x][y]<0 && mayorN==0)||(matriz[x][y]<0 && mayorN!=0 && matriz[x][y]>mayorN)) mayorN=matriz[x][y];
}
cout<<endl;
}
cout<<"los valores multiplos de 3 son: [";
for(int x=0;x<indice;x++){
cout<<multiplos[x]<<",";
}
cout<<"]"<<endl;
cout<<"El promedio de los valores positivos ubicados en columnas pares es: "<<suma/cant<<endl;
cout<<"El Mayor valor entre los valores negativos ingresados a la matriz es: "<<mayorN<<endl;
return 0;
}