Jump to content

Algorithms/Find maximum/c method 1

From Wikibooks, open books for an open world

c source code

int findmax(const int a[], int len) {
	int curr_max, i;
	
	if(len == 1)
		return a[0];
	else if(len == 0)
		return 0;
	
	curr_max = a[0];
	for(i = 1; i < len; i++)
		if(a[i] > curr_max)
			curr_max = a[i];
	
	return curr_max;
}