Answer the question
In order to leave comments, you need to log in
How to bubble sort array elements in VBA?
Set to zabatsat an array with 3 tasks. The first one was done, but the last 2 I can't master. For some reason, the calculation of the product of array elements located between the maximum and minimum elements does not work, and you also need to arrange the bubble in ascending order.
Imports System.Math
Module Module1
Sub Main()
Dim i, A(5) As Integer
Dim sum As Double, p As Double
Dim min As Integer, min_zn As Double, max As Integer, max_zn As Double
Dim lStart As Integer, lEnd As Integer
Dim S1, S As String
sum = 0
Randomize()
For i = 0 To 5 Step 1
A(i) = Int((5 * Rnd() + 1) - 3)
S1 = "A(" & CStr(i) & ")=" & CStr(A(i))
Console.WriteLine(S1)
Next i
For i = 0 To 5 Step 1
If A(i) < 0 Then
sum = sum + A(i)
End If
Next i
Console.WriteLine("Сумма отрицательных элементов массива:" & CStr(sum))
min = 0
min_zn = A(1)
For i = 0 To 5 Step 1
If A(i) < min_zn Then
min = i
min_zn = A(i)
End If
Next i
max = 0
max_zn = A(1)
For i = 0 To 5 Step 1
If A(i) > max_zn Then
max = i
max_zn = A(i)
End If
Next i
If min > max Then
lStart = max
lEnd = min
Else
lStart = min
lEnd = max
End If
If lEnd - lStart = 1 Or lEnd - lStart = 0 Then
Console.WriteLine("Между минимальным и максимальным элементами нет чисел")
Else
For i = lStart + 1 To lEnd - 1 Step 1
p = p * A(i)
Next i
Console.WriteLine("Произведение элементов массива", CStr(p)) - <i>не выдаёт значение</i>
End If
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question