-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path5.c
36 lines (27 loc) · 693 Bytes
/
5.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// 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.
// Sample Test Cases
// Test Case 1
// Input
// -840 -288 -261 -337 -335 488 -1
// Output
// -261
#include<stdio.h>
#include<limits.h>
int main()
{
int n,fl,sl;
fl=sl=INT_MIN;
do{
scanf("%d",&n);
if(n>fl && n!=-1)
{
sl=fl;
fl=n;
}
else if(n>sl && n!=-1)
sl=n;
}while(n!=-1);
printf("%d",sl);
}