|
|||
Лабораторная работа №1. ПрограммаЛабораторная работа №1 Текст программы
Sub mass() n = 10 ReDim a(n) Rem Rem ввод элементов массива Rem For i = 1 To n a(i) = Cells(i, 2) Next i Rem Rem поиск полусуммы Max и Min элементов Rem Max = a(1) Min = a(1) For i = 2 To n If a(i) > Max Then Max = a(i) If a(i) < Min Then Min = a(i) Next i Ps = (Max + Min) / 2 Cells(1, 5) = Max Cells(2, 5) = Min Cells(3, 5) = Ps Rem Rem поиск суммы +эл.с четными индексами и произведения -эл.с нечет. индексами Rem s = 0 p = 1 For i = 2 To n Step 2 If a(i) > 0 Then s = s + a(i) Next i For i = 1 To n Step 2 If a(i) < 0 Then p = p * a(i) Next i Cells(4, 5) = s Cells(5, 5) = p Rem Rem поиск первого дробного элемента Rem f = 0 For i = 1 To n If a(i) <> Int(a(i)) Then f = 1 Cells(6, 5) = a(i) Exit For End If Next i If f = 0 Then Cells(6, 5) = "no drobn.el-tov" Rem Rem поиск последнего элемента кратного 2 Rem f = 0 For i = n To 1 Step -1 If a(i) Mod 2 = 0 Then f = 1 Cells(7, 5) = a(i) Exit For End If Next i If f = 0 Then Cells(7, 5) = "no el-tov kratn. 2" Rem Rem найти среднее элементов Rem s = 0 For i = 1 To n s = s + a(i) Next i
sr = s / n Cells(8, 5) = sr
Rem Rem найти среднее +элементов Rem Rem s = 0 k = 0 For i = 1 To n If a(i) > 0 Then s = s + a(i) k = k + 1 End If Next i If k = 0 Then Cells(9, 5) = "no el-tov" Else sr = s / k Cells(9, 5) = sr End If Rem Rem найти среднее +целочисленных элементов Rem s = 0 k = 0 For i = 1 To n If a(i) > 0 And a(i) = Int(a(i)) Then s = s + a(i) k = k + 1 End If Next i If k = 0 Then Cells(10, 5) = "no el-tov" Else sr = s / k Cells(10, 5) = sr End If
Rem Rem подсчитать кол-во +, - , 0 -элементов Rem k1 = 0 k2 = 0 k3 = 0 For i = 1 To n If a(i) > 0 Then k1 = k1 + 1 If a(i) < 0 Then k2 = k2 + 1 If a(i) = 0 Then k3 = k3 + 1 Next i Cells(11, 5) = k1 Cells(12, 5) = k2 Cells(13, 5) = k3 End Sub
Программа
|
|||
|