I want to implement a function that returns the minimum of four elements. I have written the following code:
#include <stdio.h>
int max_of_four(int a, int b, int c, int d) {
int max;
if (a > b) {
if (a > c) {
if (a > d) {
max = a;
}
}
} else if (b > a) {
if (b > c) {
if (b > d) {
max = b;
}
}
} else if (c > a) {
if (c > b) {
if (c > d) {
max = c;
}
}
} else {
max = d;
}
return max;
}
int main() {
// initializing int a, b, c, d, max;
scanf("%d %d %d %d", &a, &b, &c, &d);
int ans = max_of_four(a, b, c, d);
printf("%d", ans);
return 0;
}
This code is giving me output 6422164 irrespective of the input. What is wrong with my code?