// ex_ch10_4.c -- the index of the largest value
#include <stdio.h>
#define SIZE 5

int largest_index(const double arr[], int n);

int main(void)
{
	const double values[SIZE] = {4.4, 6.6, 1.1, 3.3, 2.2};

	printf("The index of the largest value is %d.\n",
	       largest_index(values, SIZE));
	
	return 0;
}

int largest_index(const double arr[], int n)
{
	/* this is somehow broken cause it does not deal with negative
	   numbers */
	double current_largest = 0.0;
	int largest_index, i;
	
	for (i = 0; i < n; i++)
		if (arr[i] > current_largest)
		{
			current_largest = arr[i];
			largest_index = i;
		}
	
	return largest_index;
}
