-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxNumber.c
More file actions
43 lines (38 loc) · 780 Bytes
/
maxNumber.c
File metadata and controls
43 lines (38 loc) · 780 Bytes
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
37
38
39
40
41
42
43
#include <stdio.h>
/* int max_of_four(int a, int b, int c, int d)
{
if (a > b && a > c && a > d)
{
return a;
}
else if (b > c && b > d)
{
return b;
}
else if (c > d)
{
return c;
}
else
{
return d;
}
} */
// Another way to solve with "ternary operators"
int max_of_four(int a, int b, int c, int d)
{
return (a > b && a > c && a > d) ? a : (b > c && b > d) ? b
: (c > d) ? c
: d;
}
int main()
{
int a, b, c, d, ans;
scanf("%d\n", &a);
scanf("%d\n", &b);
scanf("%d\n", &c);
scanf("%d", &d);
ans = max_of_four(a, b, c, d);
printf("%d", ans);
return 0;
}