Consider what happens if all the numbers in the array are negative. Then the if(a[i]>max) will never return true. There are two ways you can do this. Either set max to INT_MIN or set max to a[0] and loop from 1 to n then.
Reputation Points: 453
Solved Threads: 57
Posting Virtuoso
Offline 1,873 posts
since May 2007