1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

FInd the largest number in array?

Discussion in 'C' started by kabirk007, Jan 27, 2009.

  1. kabirk007

    kabirk007 New Member

    FInd the largest number in array?
     
  2. asadullah.ansari

    asadullah.ansari 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 a moderator: Jan 27, 2009
    shabbir likes this.
  3. zamjad

    zamjad New 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;
    
     

Share This Page