this program gave correct anwer only for 2 testcase after it donot give desireable output.please debug it
Very first, please try putting your code in proper indented blocks. It becomes tough for people to first indent it and then read. You may try posting ideone link as well.
Secondly, talking about your code, lets say you give the input as
4 5 2, as per your code, answer will be 2. Because you are judging the second maximum only on the basis of z.
Hope it clears…