Advertisement
Namaru

Demostracion de Algorimo de Busqueda Lineal

May 2nd, 2023
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | Source Code | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace liNEAL
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.            
  14.             char leter;
  15.             char[] letra = new char[26];
  16.             for (int i = 0; i < 26; i++)
  17.             {
  18.                 letra[i] = (char)((int)+65+i);              
  19.             }
  20.             //Aqui comienza el algoritmo
  21.             Console.WriteLine("Ingrese una letra: ");
  22.             leter = Convert.ToChar(Console.ReadLine().ToUpper()); //Paso 1
  23.  
  24.             //Paso 2
  25.             for (int i = 0; i < 26; i++)
  26.             {
  27.                 if (leter == Convert.ToChar(letra[i]))
  28.                 {
  29.                     Console.WriteLine("Se encontro la: " + leter + " letra en " + (i + 1) + " posicion"); //Paso 3
  30.                     break;
  31.                 }
  32.                 else if (i == 25)
  33.                 {
  34.                     //Paso 3
  35.                     Console.WriteLine("No encontro la: " + leter + " letra en el arreglo ");
  36.                     break;
  37.                 }
  38.             }
  39.             Console.ReadKey();
  40.         }
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement