Hacer un programa o algoritmo que permita mostrar artículos de abarrotes ordenados por mayor precio y mostrar los 5 artículos de menor precio.
Solución
- Entrada: Arroz 29, Papa 15, Azúcar 10, Pan 2, Jabón 5,Harina 16,Leche 45
- Salida: Leche 45, Arroz 29, Harina 16, Papa 15, Azúcar 10, Jabón 5, Pan 2
Public Class Form1 Dim w As Integer = 0 Dim c As Integer = 0 Dim cad As String = "" Dim t, p, lon, tem As Integer Dim n, aux As String Dim Art() As String Dim Prec() As Integer Public Sub inicializar(ByVal tam As Integer) ReDim Art(tam - 1) For i As Integer = 0 To (tam - 1) Art(i) = "" Next i ReDim Prec(tam - 1) For j As Integer = 0 To (tam - 1) Prec(j) = 0 Next j End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click cad = "" lon = TextBox1.Text n = TextBox2.Text p = TextBox3.Text If (c <> lon) Then Art(c) = n Prec(c) = p c = c + 1 Else While (w <> (lon - 1)) w = 0 For k As Integer = 0 To (lon - 2) If (Prec(k) >= Prec(k + 1)) Then w = w + 1 Else tem = Prec(k) Prec(k) = Prec(k + 1) Prec(k + 1) = tem aux = Art(k) Art(k) = Art(k + 1) Art(k + 1) = aux End If Next k End While For x As Integer = 0 To (lon - 1) cad = cad + "Articulo : " + Art(x) + " Precio : " + Trim(Prec(x)) & vbCrLf Next x TextBox4.Text = cad End If End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged t = TextBox1.Text If (t < 6) Then MsgBox("Ingrese como minimo 6 articulo", MsgBoxStyle.Information) Else inicializar(t) End If End Sub End Class
0 comentarios:
Publicar un comentario