// PascalABC.NET 3.0, сборка 1156 от 30.01.2016 function Avg(a:array[,] of integer):real; begin var s:=0; var k:=0; foreach var e:integer in a do if e>0 then begin s+=e; Inc(k) end; if k>0 then Result:=s/k else Result:=1e-100; end;
begin var A:=MatrixRandom(4,4,-50,50); Writeln(A); Writeln('Среднее арифметическое положительных равно ',Avg(A):0:3); var B:=MatrixRandom(5,5,-30,30); Writeln(B); Writeln('Среднее арифметическое положительных равно ',Avg(B):0:3); var C:=MatrixRandom(4,5,-25,38); Writeln(C); Writeln('Среднее арифметическое положительных равно ',Avg(C):0:3); end.
Тестовое решение: [[35,35,5,-47],[14,34,35,-13],[25,-5,35,-29],[-7,10,-12,12]] Среднее арифметическое положительных равно 24.000 [[-12,-17,-10,19,14],[20,17,-27,-2,16],[-3,-21,30,2,10],[5,-3,-17,-3,18],[0,-26,29,1,-22]] Среднее арифметическое положительных равно 15.083 [[-5,-11,17,-4,15],[15,17,-24,36,15],[-8,-3,-22,28,-25],[-21,6,12,31,-1]] Среднее арифметическое положительных равно 19.200
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim Array() As Byte = {102, 103, 105, 105, 104, 108, 101, 109, 111, 113} GnomeSort(Array, True) End Sub
' // Алгоритм гномьей сортировки Sub GnomeSort(ByRef Array() As Byte, ByVal ToUpper As Boolean) Dim tui As Integer, index As Integer, last As Integer If (ToUpper = True) Then tui = 1 Else tui = -1 index = 1 last = 2 Do If ((Array(index) * tui) < (Array(index - 1) * tui)) Then SWAP(Array(index), Array(index - 1)) index -= 1 If (index = 0) Then index = last last += 1 End If Else index = last last += 1 End If Loop While (index < (UBound(Array) + 1)) ' // c2fbefeeebede8eb3a20caf3eff0e8ffedeee220c42ec52e2028632920442d6d6f6e3535 End Sub
' // Функция обмена двух переменных Private Function SWAP(ByRef ic_a As Integer, ByRef ic_b As Integer) As Boolean Dim Dump As Integer = ic_a ic_a = ic_b ic_b = Dump Return True End Function
0,0(0 оценок)
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota
Оформи подписку