Предмет:
ИнформатикаАвтор:
mckeeОтвет:
Сгенерируем 100 случайных чисел в диапазоне -99...99 и заполним ими массив:
Dim Array(99) As Integer
Dim Randomize Timer
For i = 0 To 99
Array(i) = -99 To 99
Next i
Выведем массив 10 чисел в строке:
For i = 0 To 9
Row = Row + 1
If Row Mod 10 = 1 Then Print Row
For j = 0 To 9
Print Array(i * 10 + j); " ";
Next j
Next i
Определим функции и вызовем их:
Function getAverage(array() As Integer, size As Integer) As Float
Dim sum As Integer = 0
For i = 0 To size - 1
sum = sum + array(i)
Next i
getAverage = sum / size
End Function
Print getAverage(Array, 100) ' 10.7
Function negCount(array() As Integer, size As Integer) As Integer
Dim count As Integer = 0
For i = 0 To size - 1
If array(i) < 0 Then count = count + 1
Next i
negCount = count
End Function
Print negCount(Array, 100) ' 3
Function zeroIndex(array() As Integer, size As Integer) As Integer
Dim index As Integer = 0
For i = 0 To size - 1
If array(i) = 0 Then index = i
Next i
If index = 0 Then zeroIndex = -1 Else zeroIndex = index
End Function
Print zeroIndex(Array, 100) ' 2
Function getMin(array() As Integer, size As Integer) As Integer
Dim min As Integer = array(0)
For i = 1 To size - 1
If array(i) < min Then min = array(i)
Next i
getMin = min
End Function
Print getMin(Array, 100) '-76
Function getMax(array() As Integer, size As Integer) As Integer
Dim max As Integer = array(0)
For i = 1 To size - 1
If array(i) > max Then max = array(i)
Next i
getMax = max
End Function
Print getMax(Array, 100) ' 90
Function getRangeSum(array() As Integer, size As Integer) As Integer
Dim min1 As Integer = getMin(Array, 100)
Dim max1 As Integer = getMax(Array, 100)
Dim sum As Integer = 0
For i = 0 To size - 1
If array(i) >= min1 And array(i) <= max1 Then sum = sum + array(i)
Next i
getRangeSum = sum
End Function
Print getRangeSum(Array, 100) ' 59
Объяснение:
отметь как лучший ответ
Автор:
maximus0x4cДобавить свой ответ
Предмет:
Українська літератураАвтор:
imogenОтветов:
Смотреть