File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Codechef Problems/DSA Learning Series Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ /* Given three distinct integers A, B and C, print the second largest number among them.
2
+
3
+ Input:
4
+ The input consists of three lines.
5
+ The first line contains a single integer A.
6
+ The second line contains a single integer B.
7
+ The third line contains a single integer C.
8
+ Output:
9
+ Print the second largest number among A, B and C, in a separate line.
10
+
11
+ Constraints
12
+ 1≤A,B,C≤109
13
+ Sample Input 1:
14
+ 2
15
+ 7
16
+ 21
17
+ Sample Output 1:
18
+ 7
19
+ Sample Input 2:
20
+ 14
21
+ 28
22
+ 16
23
+ Sample Output 2:
24
+ 16
25
+ EXPLANATION:
26
+ In the first example, 7 is the second largest number among the given three numbers.
27
+ In the second example, 16 is the second largest number among the given three numbers. */
28
+
29
+ #include <stdio.h>
30
+
31
+ int main (void ) {
32
+
33
+ int n1 ,n2 ,n3 ;
34
+ scanf ("%d\n%d\n%d" ,& n1 ,& n2 ,& n3 );
35
+ if (((n1 > n2 )&& (n1 < n3 ))|| ((n1 < n2 )&& (n1 > n3 )))
36
+ {
37
+ printf ("%d" ,n1 );
38
+ }
39
+ else if (((n2 > n1 )&& (n2 < n3 ))|| ((n2 < n1 )&& (n2 > n3 )))
40
+ {
41
+ printf ("%d" ,n2 );
42
+ }
43
+ else
44
+ {
45
+ printf ("%d" ,n3 );
46
+ }
47
+
48
+ return 0 ;
49
+ }
You can’t perform that action at this time.
0 commit comments