FInd the largest number in array?

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

  1. kabirk007

    kabirk007 New Member

    Joined:
    Dec 2, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    FInd the largest number in array?
     
  2. asadullah.ansari

    asadullah.ansari TechCake

    Joined:
    Jan 9, 2008
    Messages:
    356
    Likes Received:
    14
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    NOIDA
    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

    Joined:
    Oct 7, 2008
    Messages:
    15
    Likes Received:
    1
    Trophy Points:
    0
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice