FInd the largest number in array?

kabirk007's Avatar, Join Date: Dec 2008
Light Poster
FInd the largest number in array?
asadullah.ansari's Avatar, Join Date: Jan 2008
TechCake
find on google, You can get easily... ...
Code:
#include <stdio.h>

int main ()
{
  int arr[] = {1, 20, 9, 12, 19, 17, 10, 5};
  printf ( "%d\n", arr[FindMaxArr ( arr, 0, 8 )] );
  return 0;
}
int FindMaxArr( int arr[], int lMost, int rMost )
{
  if ( lMost == rMost - 1 )     return lMost;  
  rMost = FindMaxArr( ( arr, lMost+ 1, rMost);
  return arr[rMost] > a[lMost] ? rMost : lMost;
}

Last edited by shabbir; 27Jan2009 at 14:43.. Reason: Code blocks
zamjad's Avatar, Join Date: Oct 2008
Go4Expert Member
Sorry to tell you but again your this code has compilation error.

1. First you have to give the signature of the function before main if you define it after main. So you have to write this line before main

Code:
int FindMaxArr( int arr[], int lMost, int rMost );
2. Second there is an extra "(" when calling function recursively. It should be like this

Code:
rMost = FindMaxArr ( arr, lMost+ 1, rMost);
3. Third there is no variable named "a" it should be arr like this

Code:
return arr[rMost] > arr[lMost] ? rMost : lMost;