second max of three no

this program gave correct anwer only for 2 testcase after it donot give desireable output.please debug it

#include<stdio.h>
int main()
{
int x,y,z,max,max1;
while((scanf("%d%d%d",&x,&y,&z)>0))
{
max=x>y?x:y;
max1=max>z?z:max;
printf("%d\n",max1);
}
return 0;
}

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… :slight_smile: