Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   FInd the largest number in array? (http://www.go4expert.com/forums/largest-array-t15952/)

kabirk007 27Jan2009 13:50

FInd the largest number in array?
 
FInd the largest number in array?

asadullah.ansari 27Jan2009 14:39

Re: FInd the largest number in array?
 
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;
}


zamjad 29Jan2009 21:41

Re: FInd the largest number in array?
 
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;


All times are GMT +5.5. The time now is 08:00.