using System;
namespace Practica1Tema3
{
public class Practica1Tema3
{
// Ingresar Lista de números
public static int[] IngresaDatos()
{
int[] arreglo = new int[5]; // 5 elementos
Console.WriteLine("Ingresame 5 numeros que sean enteros:");
for (int i = 0; i < arreglo.Length; i++)
{
Console.Write("Elemento ingresado ---> #" + (i + 1) + " : ");
arreglo[i] = int.Parse(Console.ReadLine());
}
return arreglo;
}
// Método Burbujita
public static void Bubble(int[] arreglo)
{
int n = arreglo.Length;
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (arreglo[j] > arreglo[j + 1])
{
// Iteraciones
int temp = arreglo[j];
arreglo[j] = arreglo[j + 1];
arreglo[j + 1] = temp;
}
}
}
}
// Mostrar arreglito ya ordenado
public static void MostrarArreglo(int[] arreglo)
{
Console.WriteLine("Arreglo ordenado ascendentemente:");
foreach (int num in arreglo)
{
Console.Write(num + " >>> ");
}
Console.WriteLine();
}
// Funciones
public static void Main(string[] args)
{
int[] datos = IngresaDatos(); // Ingresar
Bubble(datos); // Ordenar
MostrarArreglo(datos); // Mostrar
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: