you need to understand what is happening in this loop.
you are only checking values at j and j+1 position in the array, and replacing the previous value of k with the new value.
you need to check whether the new value the you get from the max function is greater than the value of k or not, if not then you should not replace it.
you need to write the code on your own.
Welcome to the Ranch
What did you expect to happen and what actually happened? You need to tell us that if we are to help. Also, I have added code tags, which you shouldalways use, and you can see how much better the code looks.