![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
21/04/2010, 22:08
|
| | Fecha de Ingreso: noviembre-2009
Mensajes: 79
Antigüedad: 15 años, 3 meses Puntos: 2 | |
Respuesta: Problemas para ordenar numeros Buenas noches, ya hice todo ya lo resolví pero tengo un problema grande!!!
Tengo el for (int x = 0; x < 5; x++) para indicra hasta cual numero hacer el intercambio
Si coloco x=0, x=1, x=2 x=3 todo marcha a la perfeccion si lo coloco manual en el codigo, pero cuando lo corro con el form no me da el mismo resultado
Este es el resultado manual 54321
15432
21543
32154
43215
Pero el resultado con el for es este 54321
25431
32541
43251
54321
este es el codigo
int[] num = new int[5];
int aux=0,i=0,c=0,b=0;
for (int a = 0; a < 5; a++)
{
Console.WriteLine("ingresa el numero (" + a + ")");
num[a] = int.Parse(Console.ReadLine());
} for (int x = 0; x < 5; x++)
{
for (i = 0; i < 5; i++)
{
for (c = x; c < 4; c++)
{
if (num[i] > num[c])
{
aux = num[c];
num[c] = num[i];
num[i] = aux;
}
}
} if (x > 1)
{
for (i = 0; i < x; i++)
{
for (c = 0; c < x - 1; c++)
{
if (num[i] > num[c])
{
aux = num[c];
num[c] = num[i];
num[i] = aux;
}
}
}
}
for (b = 0; b < 5; b++)
{
Console.Write(num[b] + ",");
}
Console.WriteLine();
}
Console.ReadLine();
muchas grasias a tu respuesta |