Francisco Aldana Hernández

Francisco Aldana Hernández
Sistemas Computacionales

lunes, 1 de noviembre de 2010

Programa para ordenar ascendentemente una Matriz de 3*3

#include"iostream.h"
#include"conio.h"
#include"stdio.h"
int ordenar(int lista[3][3])
{
  int c1,c2,c3,c4,aux,aux2;
for(c4=0;c4<=2;c4++)
{
for(c3=0;c3<=2;c3++)
{
for(c1=0;c1<=2;c1++)
  {
     for(c2=0;c2<=2;c2++)
     {
          if(lista[c3][c2]>lista[c3][c2+1])
          {
             aux=lista[c3][c2];
             lista[c3][c2]=lista[c3][c2+1];
             lista[c3][c2+1]=aux;
          }
        }
     }
      if(lista[c3][c4]>lista[c3][c4+1])
          {
         aux2=lista[c3][c4];
             lista[c3][c4]=lista[c3][c4+1];
             lista[c3][c4+1]=aux2;
          }
}
}



  return 0;
}
int main()
{
int c,c2,lista[3][3];
clrscr();
for(c2=0;c2<3;c2++)
{
  for(c=0;c<=2;c++)
  {
     cout<<"Introduce un numero en la posicion---> "<<c2<<" , "<<c<<": "; cin>>lista[c2][c];
  }
}
ordenar(lista); clrscr();
printf("Lista en forma ascendente:\n");
printf("\n----------------------------\n");
for(c=0;c<=2;c++)
 {
     for(c2=1;c2<=3;c2++)
     {
     cout<<lista[c][c2]<<" ";   
}
cout<<endl;
}
getch();
}

No hay comentarios:

Publicar un comentario