Search in array Learn programming Visual Basic (VB.net)



Lesson:

Arrays, Structures and Strings


Exercise:

Search in array


Objetive:

Create a Visual Basic (VB.net) program that says if a data belongs in a list that was previously created.

The steps to take are:
- Ask the user how many data will he enter.
- Reserve space for that amount of numbers (floating point).
- Request the data to the user
- Later, repeat:
* Ask the user for a number (execution ends when he enters "end" instead of a number).
* Say if that number is listed or not.

Must be done in pairs. but you must provide a single source file, containing the names of both programmers in a comment.


Code:

Imports System
Public Class exercise73
    Public Shared Sub Main()
        Console.Write("Cuantos datos reservo: ")
        Dim repeticiones As Integer = Convert.ToInt32(Console.ReadLine())
        Dim numero As Single
        Dim listaNumeros As Single() = New Single(repeticiones - 1) {}

        For i As Integer = 1 To repeticiones
            Console.Write("Dime numero {0} para guardar en la lista: ", i)
            listaNumeros(i) = Convert.ToSingle(Console.ReadLine())
        Next

        Console.Write("Que numero comprueba en la lista? ")
        numero = Convert.ToSingle(Console.ReadLine())

        While Console.ReadLine() <> "end"

            For i As Integer = 1 To repeticiones
                If listaNumeros(i) = numero Then Console.WriteLine("El número {0} existe en la lista", numero)
            Next
        End While
    End Sub
End Class



Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.