-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.c
72 lines (61 loc) · 1.37 KB
/
1.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
/*
Add `int max_of_four(int a, int b, int c, int d)` here.
*/
int max_of_four(int p,int q,int r,int s){
if(p>q){
if(p>r){
if(p>s)
return p;
else {
return s;
}
}
}
else{if(q>r){
if(q>s)
return q;
else return s;
}
else if(r>s)
{ return r;}
else
return s;
}}
int main() {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
int ans = max_of_four(a, b, c, d);
printf("%d", ans);
return 0;
}
/* error
Solution.c: In function ‘max_of_four’:
Solution.c:24:6: error: control reaches end of non-void function [-Werror=return-type]
}}
^
cc1: some warnings being treated as errors*/
/*better approach */
#include <stdio.h>
/*
Add `int max_of_four(int a, int b, int c, int d)` here.
int max_of_four(int p, int q, int r, int s) {
int max = p; // Assume p is the max
if (q > max) {
max = q; // Update max if q is greater
}
if (r > max) {
max = r; // Update max if r is greater
}
if (s > max) {
max = s; // Update max if s is greater
}
return max; // Return the maximum value
}
int main() {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
int ans = max_of_four(a, b, c, d);
printf("%d", ans);
return 0;
}*/