• Miércoles 8 de Mayo de 2024, 01:23

Autor Tema:  Ascendente Y Descendente En Una Matriz  (Leído 6495 veces)

kaka025

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
Ascendente Y Descendente En Una Matriz
« en: Sábado 24 de Noviembre de 2007, 02:15 »
0
soy nuevo en c++ y  he estado haciendo un programa que ordene los numeros de manera ascendente y descente en una matriz 2*4 tengo el siguiente codigo les agradeceria si me ayudaran, solo he estado trabajando en estos momentos de manera ascendente:

#include <stdio.h>
#include<conio.h>

 main()

{

 

   int i,j,k,l,c,temp;
   int  a[2][4];
   
   c=4;
   l=4;

   printf ("Introduzca los valores a la matriz 2*4 \n");
 

  for(i=0; i<=1;i++)
  {
    for(j=0;j<=3;j++)
     {
        gotoxy(l,c);
        scanf("%d",& a[j]);
        l+=5;
     }
        l=4;
        c++;
  }
   clrscr();

   printf("\n\n Datos de la matriz \n");
   gotoxy(l-1,c-1);
   printf("--------------------");

   for(i=0;i<=1;i++)
   {
    for(j=0;j<=3;j++)
     {
      gotoxy(l,c);
      printf("l");
      gotoxy(l+3,c);
      printf("%d",a[j]);
      l+=8;
     }
        gotoxy(l-1,c);
        printf("l");
        c++;
        l=4;
        gotoxy(l,c);
        printf("-------------");
     c++;
     }
    printf("\n\n numeros ascendentes:\n");

     for(i=0;i<=1;i++)
   {
    for(j=i+1;j<=3;j++)
     {
     
      for (k=0;k<a[j];k++)
       
   
       if(a[k]>a[k][j])
       {
       temp=a[k];
       a[k]=a[k][j];
       a[k][j]=temp;
       }
     
      }
     
     }
     
   
    for(i=0;i<=1;i++)
   {
    for(j=0;j<=3;j++)
     {
 
    printf("\n %d",a[j]);

    }
    }



   return 0;



}

INVINCIBLE

  • Nuevo Miembro
  • *
  • Mensajes: 2
    • Ver Perfil
Re: Ascendente Y Descendente En Una Matriz
« Respuesta #1 en: Domingo 25 de Noviembre de 2007, 01:42 »
0
OLAS ...OE MAN..PERO K ES LO K INTENTAS ACER..KOPIE TU CODIGO Y AL MOMENTO DE CORRERLO NO APARECE NADA DE NADA.....LO SOLUCIONE CON UN GETCH() AL FINAL DE TU MAIN...PERO.......LUEGO ME APARECEN LOS DATOS DE MATRIZ Y ENSEGUIDA UN ERROR....KREO K TU CODIGO ESTA BIEN...PERO FALTA K DEFINAS CIERTAS COSAS...
 KUANDO DEFINES K KIERAS ORDENAR LA MATRIZ ASCENDENTEMENTE... LO KIERES POR FILAS O COLUMNAS O KIERES UN SANCOCHADO:
 EJEMPLO: MATRIZ 2*2
  3   10                                
  1   9
 KIERES K APAREZCA:
//POR FILAS            //POR COLUMNAS              //POR ORDEN ASCENDENTE
  1  4                          1   9                               //FILAS Y COLUMNAS  
  2   9                         3   10                                     1         2
                                                                               4         9