Answer:
I will code in JAVA.
Preconditions:
- The float array of data are declared and initialized.
public float sumArray(float[] data) {
float sum = 0;
for(int i = 0; i < data.length; i++) {
sum = sum + data[i];
}
return sum;
}
Explanation:
First, you have to declare a variable sum of type float and initialize with 0. In addition, this method has a for-loop to go through whole array of data and each element is added to the float value to sum. When the for loop ends, the sum variable is returned.
Answer:
# Program to find kth element
# from two sorted arrays
def kth(arr1, arr2, m, n, k):
sorted1 = [0] * (m + n)
i = 0
j = 0
d = 0
while (i < m and j < n):
if (arr1[i] < arr2[j]):
sorted1[d] = arr1[i]
i += 1
else:
sorted1[d] = arr2[j]
j += 1
d += 1
while (i < m):
sorted1[d] = arr1[i]
d += 1
i += 1
while (j < n):
sorted1[d] = arr2[j]
d += 1
j += 1
return sorted1[k - 1]
# driver code
arr1 = [2, 3, 6, 7, 9]
arr2 = [1, 4, 8, 10]
k = 5;
print(kth(arr1, arr2, 5, 4, k))
The running time will be O(n) and O(log k)
<h3>f7 should open the spelling and grammer dialog box</h3>