#include <stdio.h>
int max_of_four(int a, int b, int c, int d) {
int max = a;
if (b > max)
max = b;
if (c > max)
max = c;
if (d > max)
max = d;
return max;
}
int main() {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
int result = max_of_four(a, b, c, d);
printf("%d\n", result);
return 0;
}
Let's go through the solution step by step:
We include the
We define a function called max_of_four that takes four integer parameters a, b, c, and d and returns an integer value.
Inside the max_of_four function, we initialize a variable max with the value of the first parameter a.
We compare each of the remaining parameters b, c, and d with the current maximum value max and update max if a larger value is found.
Finally, we return the maximum value max from the max_of_four function.
In the main() function, we declare four integers a, b, c, and d to store the input values.
We use the scanf() function to read input from the user and store it in the respective variables a, b, c, and d.
We call the max_of_four function with the input values a, b, c, and d, and assign the returned maximum value to a variable result.
We use the printf() function to print the result variable, which represents the maximum of the four input numbers.
By providing the expected input and executing the code, you should see the desired output according to the problem statement on HackerRank.