viernes, 19 de diciembre de 2014

matriz de 5x6


Desarrollar un programa que ingrese elementos en una matriz de 5x6 y
luego pida un número X y un Número Y, para que reemplace al mayor y menor
número respectivamente de todos los elementos de dicha matriz.

#include<iostream>
using namespace std;
int main (){
int mayor=0,menor=100,i,j,x,y;
int A[5][6];
cout<<"ingrese los elementos de la matriz "<<endl;
for(i=0;i<5;i++){
for(j=0;j<6;j++){
cout<<"# "<<i+1<<" , "<<j+1 <<"  =  " ;
cin>>A[i][j];
}
cout<<endl;
}
for(i=0;i<5;i++){
for(j=0;j<6;j++){
if(A[i][j]>mayor){
mayor=A[i][j];
}
}
}
for(i=0;i<5;i++){
for(j=0;j<6;j++){
if(A[i][j]<=menor){
menor=A[i][j];
}
}
}
cout<<"matriz"<<endl;
for(i=0;i<5;i++){
for(j=0;j<6;j++){
cout<<A[i][j]<<" ";
}
cout<<endl;
}
cout<<"ingrese un numero para reemplazar al mayor "<<endl;cin>>x;
cout<<"ingrese un numero para reemplazar al menor "<<endl;cin>>y;
for(i=0;i<5;i++){
for(j=0;j<6;j++){
if(A[i][j]==mayor){
A[i][j]=x;
}
else
if(A[i][j]==menor){
A[i][j]=y;
}
}
}
cout<<"la nueva matriz "<<endl;
for(i=0;i<5;i++){
for(j=0;j<6;j++){
cout<<A[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
//J.
BAJATE EL CODIGO

http://www.linkbucks.com/BOFi1






No hay comentarios:

Publicar un comentario