jueves, 8 de julio de 2010

C#: Busqueda de elementos dentro de un Array

using System;

using System.Text;

using c = System.Console;

namespace BusquedaArray

{

class busqueda_elementos_dentro_de_un_array

{

string[] arreglo;

string elemento;

string posicion;

busqueda_elementos_dentro_de_un_array()

{

arreglo = new string[10];

posicion = "";

}

void cuerpo()

{

c.WriteLine("◙◙◙◙▄▄▄▄▄ ┼┼☼☼☼ Ingrese un Numero de Veces ☼☼☼┼┼ ▄▄▄▄▄◙◙◙◙");

int n = int.Parse(c.ReadLine());

for (int i = 0; i <n;i++)

{

c.WriteLine("░░░░░░░Ingrese elemento:{0}░░░░░░░", i + 1);

arreglo[i] = c.ReadLine().ToLower();

}

c.WriteLine("◙◙◙◙Mostrardo elementos del Arreglo◙◙◙◙");

for (int i = 0; i <n;i++)

{

c.Write("{0}\t ", arreglo[i]);

}

c.WriteLine("");

c.WriteLine("");

c.WriteLine("░░░░░░░Ingrese elemento que desea buscar en el arreglo:░░░░░░░");

elemento = c.ReadLine().ToLower();

c.WriteLine("");

c.WriteLine("");

for (int i = 0; i <10;i++)

{

if (arreglo[i] == elemento)

{

posicion = posicion + ' ' + i;

}

}

c.WriteLine("░░░░░░░El elemento se encuantra en las posiciones:{0}░░░░░░░", posicion);

}

static void Main(string[] args)

{

c.ForegroundColor = ConsoleColor.Red;

c.BackgroundColor = ConsoleColor.Yellow;

c.Clear();

busqueda_elementos_dentro_de_un_array obj = new busqueda_elementos_dentro_de_un_array();

obj.cuerpo();

c.ReadLine();

}

}

}

No hay comentarios:

Publicar un comentario

*Dejanos Tus Comentarios*