[ILUG] OT: max function
John P. Looney (Kate)
jplooney-ilug at online.ie
Mon May 22 11:32:50 IST 2000
On Fri, May 19, 2000 at 07:36:36AM -0700, Michael Turley mentioned:
> Anyone got a C function which calculates the maximum
> value in an array that they'd like send to me?
Sounds like your homework ;)
int arraymax(int *array, int arraysize)
{
int i;
int max= (*array); //Max is first element in the array
for(i=1;i<arraysize;i++) { //From the 2nd element, to the end
if(*(array+i)<max) { //If what we are looking at is bigger than max...
max=*(array+i);
}
}
}
BTW, passing an array to a function gives the function a pointer to the
array to the first element in the array - C doesn't pass the whole struct
to it (like you can in C++).
Kate
--
"The fool must be beaten with a stick, for an intelligent person
the merest hint is sufficient" -- Zen Master Greg
More information about the ILUG
mailing list