
Mayores y menores en C++
Publicado por david (8 intervenciones) el 28/09/2022 15:35:16
Buenas
Me piden extraer el numero mayor y el numero menor de una matriz, mediante una funcion, no me sale el codigo, alguno me podria ayudar?
Me piden extraer el numero mayor y el numero menor de una matriz, mediante una funcion, no me sale el codigo, alguno me podria ayudar?
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
#include<iostream>
using namespace std;
void funcion (int i, int j,int mayor=0)
{
int matriz [2][3];
cout<<"La matriz:\n";
for (i=0;i<2;i++)
{
for (j=0;j<3;j++)
{
cout<<matriz[i][j];
}
cout<<endl;
}
mayor= matriz[0][0];
for (i=0;i<2;i++)
{
for (j=0;j<3;j++)
{
if (mayor<matriz[i][j])
{
mayor=matriz[i][j];
}
}
}
cout<<"El numero mayor es: "<<mayor;
}
int main ()
{
int matriz [2][3],i,j,mayor=0;
for (i=0;i<2;i++)
{
for (j=0;j<3;j++)
{
cin>>matriz[i][j];
}
}
funcion(i,j,mayor);
}
Valora esta pregunta


0