Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created Jun 11, 2021
Embed
What would you like to do?
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