Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created June 11, 2021 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/93bf5379768fb87641bdef4361c63f50 to your computer and use it in GitHub Desktop.
Save parzibyte/93bf5379768fb87641bdef4361c63f50 to your computer and use it in GitHub Desktop.
using System;
// https://parzibyte.me/blog
namespace App
{
class Programa
{
static int buscarIndice(int[] arreglo, int busqueda)
{
for (int i = 0; i < arreglo.Length; i++)
{
if (arreglo[i] == busqueda)
{
return i;
}
}
return -1;
}
static void Main(string[] args)
{
int[] numeros = { 999, 28, 11, 96, 1, 2, 45, 0, 1 };
int busqueda = 11;
int indice = buscarIndice(numeros, busqueda);
if (indice == -1)
{
Console.WriteLine("El elemento {0} no existe", busqueda);
}
else
{
Console.WriteLine("El elemento {0} existe en la posición {1}", busqueda, indice);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment