how to find the average value of a function code example
Example 1: how to use a function to find the average in python
avreage_cost = cost
avg = sum(avreage)/len(avreage)
print("The average amout you spent is ", round(avg,2))
Example 2: java function that returns the index of the largest value in an array
public int getIndexOfLargest( int[] array )
{
if ( array == null || array.length == 0 ) return -1; // null or empty
int largest = 0;
for ( int i = 1; i < array.length; i++ )
{
if ( array[i] > array[largest] ) largest = i;
}
return largest; // position of the first largest found
}