Give a sequence of integers as input, terminated by a -1.( -1 in the input signals the end of the input )
Program:
#include<stdio.h>
int main()
{
int prev,max1,max2,curr;
scanf("%d",&prev);
if(prev!=-1)
{
max1=prev;
scanf("%d",&curr);
while(curr!=-1)
{
if(curr>max1)
{
max2=max1;
max1=curr;
}
else max2=curr;
scanf("%d",&curr);
}
printf("%d",max2);
}
return 0;
}
Sample input and output:
8 7 6 4 5 2 4 8 9 -2 -3 8 7 -1
7