Final answer:
In the Coral Language, you can define a function named computeAverage that takes one parameter: an array of integers. This function will calculate the average of all the integers in the array.
Step-by-step explanation:
In the Coral Language, you can define a function named computeAverage that takes one parameter: an array of integers. This function will calculate the average of all the integers in the array. Here's an example implementation:
def computeAverage(userVals):
sum = 0
for num in userVals:
sum += num
average = sum / len(userVals)
return average
# Main program
size = int(input())
array = []
for i in range(size):
array.append(int(input()))
result = computeAverage(array)
print(str(result) + '.0')
In this code, the computeAverage function iterates over each element in the array and adds it to a sum variable. After iterating through all the elements, it calculates the average by dividing the sum by the length of the array. Finally, the main program reads the size of the array, fills it with user input values, calls the computeAverage function, and prints the result.