Created
May 29, 2013 10:39
-
-
Save tsyber1an/5669415 to your computer and use it in GitHub Desktop.
for_elya.vbs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SetLocale(1049) | |
msgBox GetLocale() | |
Dim i, j | |
Dim diagonalMean, mini, maxi, matrix_dim, printMessage | |
printMessage = "" | |
matrix_dim = 3 ' считаем с нуля | |
diagonalMean = 0 | |
mini = 0 | |
Dim array2D(3,3) | |
'ReDim array2D(0 To 3, 0 To 3) | |
array2D(0,0) = 1 | |
array2D(0,1) = 2 | |
array2D(0,2) = 1 | |
array2D(0,3) = 1 | |
array2D(1,0) = 1 | |
array2D(1,1) = 1 | |
array2D(1,2) = 1 | |
array2D(1,3) = 1 | |
array2D(2,0) = 1 | |
array2D(2,1) = 1 | |
array2D(2,2) = 1 | |
array2D(2,3) = 1 | |
array2D(3,0) = 1 | |
array2D(3,1) = 1 | |
array2D(3,2) = 1 | |
array2D(3,3) = 1 | |
for i = 0 to matrix_dim | |
for j = 0 to matrix_dim | |
if i = j then | |
diagonalMean = diagonalMean + array2D(i, j) | |
end if | |
next | |
next | |
diagonalMean = diagonalMean/matrix_dim | |
If diagonalMean > 0 Then | |
' find minimal in 3 raw | |
indexOfMin = GetIndexOfMin(GetRaw(array2D, 2, matrix_dim)) | |
mini = array2D(2, indexOfMin) | |
printMessage = printMessage & "Сред. ариф. диагональных элементов положительно." & vbCrLf | |
printMessage = printMessage & "Заменяем минимальный элемент третьей строки " & mini & vbCrLf | |
msgBox printMessage | |
Else | |
printMessage = printMessage & "Сред. ариф. диагональных элементов не положительно." & vbCrLf | |
maxi = Max(GetCol(array2D, 1, matrix_dim)) | |
printMessage = printMessage & "Максимальный элемент второго столбца " & maxi & vbCrLf | |
printMessage = printMessage & "делим и получаем такую матрицу " & vbCrLf | |
for i = 0 to matrix_dim | |
for j = 0 to matrix_dim | |
array2D(i, j) = array2D(i, j)/maxi | |
printMessage = printMessage & " " & array2D(i, j) | |
next | |
printMessage = printMessage & vbCrLf | |
next | |
msgBox printMessage | |
End if | |
Function GetRaw(AnArray2D(), rawNumber, dimentionOfArray2D) | |
Dim raw() | |
ReDim raw(dimentionOfArray2D) | |
For i = 0 to dimentionOfArray2D | |
For j = 0 to dimentionOfArray2D | |
If i = rawNumber Then raw(j) = AnArray2D(i, j) | |
next | |
next | |
GetRaw=raw | |
End Function | |
Function GetCol(AnArray2D(), colNumber, dimentionOfArray2D) | |
Dim col() | |
ReDim col(dimentionOfArray2D) | |
For i = 0 to dimentionOfArray2D | |
For j = 0 to dimentionOfArray2D | |
If j = colNumber Then col(i) = AnArray2D(i, j) | |
next | |
next | |
GetCol=col | |
End Function | |
Function GetIndexOfMin(AnArray()) | |
MinItem=cdbl(AnArray(0)) | |
Dim i, MinitemIndex | |
For i = LBound(AnArray, 1) To UBound(AnArray, 1) | |
If cdbl(AnArray(i)) < Minitem Then | |
MinitemIndex = i | |
Minitem = cdbl(AnArray(i)) | |
End If | |
next | |
GetIndexOfMin=MinitemIndex | |
End Function | |
Function Min(AnArray()) | |
MinItem=cdbl(AnArray(0)) | |
For Each Item In Anarray | |
If cdbl(Item) < Minitem Then Minitem = cdbl(Item) | |
next | |
min=Minitem | |
End Function | |
Function Max(AnArray()) | |
MaxItem=Cdbl(AnArray(0)) | |
For Each Item In AnArray | |
result = Maxitem < Item | |
If cdbl(Item) > MaxItem Then Maxitem = Cdbl(Item) | |
Next | |
max=Maxitem | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment