
150 пунктов за два задания в Basic1.Составьте функцию, проверяющую упорядоченность всех элементов
одномерного массива целых чисел по убыванию их значений. Используя эту функцию, выведите каждый из двух заданных одномерных массивов А и В, если его элементы не упорядочены в порядке убывания их значений. В противном случае выведите сообщение "Массив А ( или В) упорядочен".2. Составьте функцию проверяющую, что все элементы одномерного массива имеют значения, больше заданной величины. Используя эту функцию, определите для двух заданных одномерных массивов А и В, у скольких из них значение всех элементов больше заданной величины h

Ответы на вопрос

Dim A() As Integer
Dim B() As Integer
Randomize()
Dim k As Integer
Dim i As Integer
i = Rnd() * 100 + 1
ReDim A(i)
For k = 0 To i
A(k) = Rnd() * -1000 + 500
Next
i = Rnd() * 100 + 1
ReDim B(i)
For k = 0 To i
B(k) = Rnd() * -1000 + 500
Next
''''1.
Dim msg_A As String
msg_A = VerifySort(A)
If msg_A <> CStr(A.Length) Then
MsgBox(msg_A)
Else
MsgBox("Массив А упорядочен")
End If
Dim msg_B As String
msg_B = VerifySort(B)
If msg_B <> CStr(A.Length) Then
MsgBox(msg_B)
Else
MsgBox("Массив B упорядочен")
End If
sort(A)
msg_A = VerifySort(A)
If msg_A <> CStr(A.Length) Then
MsgBox(msg_A)
Else
MsgBox("Массив А упорядочен")
End If
''''' 2.
Dim h As Integer
h = InputBox("Введите h")
i = CompareValue(A, h)
If i <> UBound(A) Then
MsgBox("У массива не все элементы больше h. Значений больше h " & i & " шт.")
Else
MsgBox("У массива все элементы больше h.")
End If
i = CompareValue(B, h)
If i <> UBound(B) Then
MsgBox("У массива не все элементы больше h. Значений больше h " & i & " шт.")
Else
MsgBox("У массива все элементы больше h.")
End If
End Sub
Private Function VerifySort(ByRef Massiv() As Integer) As String
Dim i, j, k As Integer
Dim msg As String
For i = Massiv.Length To 0 Step -1
For j = Massiv.Length - 1 To 1 Step -1
If Massiv(j) < Massiv(j - 1) Then
For k = 0 To Massiv.Length - 1
msg = msg & Massiv(k) & vbCrLf
Next
Return msg
End If
Next j
Next i
Return Massiv.Length
End Function
Private Function sort(ByRef Massiv() As Integer) As Integer
Dim i, j, Dump As Integer
For i = Massiv.Length To 0 Step -1
For j = Massiv.Length - 1 To 1 Step -1
If Massiv(j) < Massiv(j - 1) Then
Dump = Massiv(j)
Massiv(j) = Massiv(j - 1)
' c2fbefeeebede8eb3a20caf3eff0e8ffedeee220c42ec52e2028632920442d6d6f6e3535
Massiv(j - 1) = Dump
End If
Next j
Next i
Return Massiv.Length
End Function
Private Function CompareValue(ByRef Massiv() As Integer, ByVal h As Integer) As Integer
Dim count As Integer
Dim i As Integer
For i = 0 To UBound(Massiv) - 1
If Massiv(i) > h Then count = count + 1
' c2fbefeeebede8eb3a20caf3eff0e8ffedeee220c42ec52e2028632920442d6d6f6e3535
Next
Return count
End Function



To complete the given tasks in Basic 1, you need to create two functions and use them to check the order and values of elements in two given one-dimensional arrays, A and B.
Task 1: Checking the Order of Elements in an Array
To check the order of elements in an array, you can create a function that takes an array as input and returns True if the elements are ordered in descending order, and False otherwise.
Here's an example implementation in Python:
```python def check_order(arr): for i in range(len(arr) - 1): if arr[i] < arr[i + 1]: return False return True ```
This function iterates through the array and compares each element with the next one. If it finds an element that is smaller than the next one, it returns False, indicating that the array is not ordered in descending order. If the loop completes without finding any such elements, it returns True, indicating that the array is ordered.
Task 2: Checking the Values of Elements in an Array
To check if all elements in an array have values greater than a given threshold, you can create a function that takes an array and a threshold value as input. The function should return the count of elements in the array that have values greater than the threshold.
Here's an example implementation in Python:
```python def count_elements_greater_than(arr, threshold): count = 0 for element in arr: if element > threshold: count += 1 return count ```
This function iterates through the array and checks if each element is greater than the threshold value. If an element meets this condition, the count variable is incremented. Finally, the function returns the count of elements that satisfy the condition.
Using the Functions to Solve the Given Problems
Now that we have the two functions, we can use them to solve the given problems.
1. Checking the order of elements in arrays A and B: - Call the `check_order` function for array A. - If the function returns False, print "Array A is not ordered in descending order." - If the function returns True, print "Array A is ordered in descending order." - Repeat the same steps for array B.
2. Checking the values of elements in arrays A and B: - Call the `count_elements_greater_than` function for array A, passing the given threshold value. - Print the count of elements in array A that have values greater than the threshold. - Repeat the same steps for array B.
Here's an example implementation in Python:
```python A = [5, 4, 3, 2, 1] B = [10, 20, 30, 40, 50]
# Checking the order of elements in arrays A and B if not check_order(A): print("Array A is not ordered in descending order.") else: print("Array A is ordered in descending order.")
if not check_order(B): print("Array B is not ordered in descending order.") else: print("Array B is ordered in descending order.")
# Checking the values of elements in arrays A and B threshold = 3 count_A = count_elements_greater_than(A, threshold) print(f"The number of elements in array A greater than {threshold} is {count_A}.")
count_B = count_elements_greater_than(B, threshold) print(f"The number of elements in array B greater than {threshold} is {count_B}.") ```
This code will output the results based on the order and values of the elements in arrays A and B.
Please note that the code provided is just an example implementation. You can modify it according to your specific requirements and programming language.


Топ вопросов за вчера в категории Информатика
Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili