You are given a sequence of integers as input, terminated by a -1. (That is, the input integers may be positive, negative or 0. A -1 in the input signals the end of the input.)
-1 is not considered as part of the input.
Find the second largest number in the input. You may not use arrays.
Test cases pass but score is 0.0
Here's the code
int main()
{
int a=-32768,b=-32768,temp=-32768;
while(1)
{
scanf("%d",&a);
if(a==-1)
break;
else if(a>0)
{
temp=b;
b=a;
}
else
{
if(a>b)
{
temp=b;
b=a;
}
else
{
temp=b;
}
}
}
printf("%d",temp);
return 0;
}