-
-
Save parzibyte/93bf5379768fb87641bdef4361c63f50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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