Error en C# me dice que esta fuera de rango
Publicado por NiNo (1 intervención) el 13/11/2015 23:01:11
Hola estoy haciendo el curso de C# voy por el capitulo 19 y no entiendo porque cuando pongo esto a funcionar no me da error, pero luego de que entro los datos se pone la parte del IF amarilla y me dice que esta fuera de rango, si alguien me explicara que estoy haciendo mal
aqui esta el cofigo
muchas gracias de ante mano
aqui esta el cofigo
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication23
{
class Ordenar
{
private int[] alm;
string tod;
int cant;
public void Entradas()
{
Console.WriteLine("Digite Cuantos Numeros Desea Ingresar");
tod = Console.ReadLine();
cant = int.Parse(tod);
alm = new int[cant];
for (int x = 0; x < alm.Length; x++)
{
Console.WriteLine("Digite un Numero en la Posicion " + (x + 1));
tod = Console.ReadLine();
cant = int.Parse(tod);
alm[x] = cant;
}
}
public void Organizar()
{
for(int x=0; x<alm.Length; x++)
{
if (alm[x] > alm[x+1])
{
for (int k=0; k < x-1; k++)
{
if (alm[k] > alm[k + 1])
{
int aux;
aux = alm[k];
alm[k] = alm[k + 1];
alm[k + 1] = aux;
}
}
}
}
}
public void Imprimir()
{
Console.WriteLine("Sus Numeros Organizados Son :");
for (int x = 0; x < alm.Length; x++)
{
Console.WriteLine(alm[x]);
}
}
static void Main(string[] args)
{
Ordenar Ord = new Ordenar();
Ord.Entradas();
Ord.Organizar();
Ord.Imprimir();
Console.ReadKey();
}
}
}
muchas gracias de ante mano
Valora esta pregunta


0