Someone's coursework?! This function is for an array of integers, the length of the array is Count.
int MaxInt(NumArray as *int, Count as int)
{
int Inst;
int Result;
Result = NumArray[0];
for (Inst=0;Inst
{
if(NumArray[Inst] > Result)
{
Result = NumArray[Inst];
}
}
return Result;
}
Chat with our AI personalities
int firstNumber,secondNumber for(firstNumber = min; firstNumber <= max; firstNumber++); { for(secondNumber = min; secondNumber <=max; secondNumber++); int result firstNumber * secondNumber; }
int sum (int min, int max) {return (max-min+1)*(max+min)/2;}
int secondmax (int a[], int n){int i, max, second;for (i=0; imax) second= max, max= a[i];else if (i==1 a[i]>second) second= a[1];}return second;}int middle (int a[3]){return secondmax (a, 3);}
** pseudo code ** if array length == 1, return first element else if array length > 1 max = first element for second item to last item if item > max max = item return max else // array length is 0 error
To find the largest of three numbers you must first find the largest of two numbers: int max (int a, int b) { return a>b?a:b; // or, equivalently: if (a>b) return a; else return b; } Now we can use this function to find the maximum of three: int max3 (int a, int b, int c) { return max (max (a,b), c); }