Summary: This C program reads four integers and determines the largest among them using a custom function. It demonstrates comparison logic and modular programming.
#include <stdio.h>
#include <limits.h>
/*
Add `int max_of_four(int a, int b, int c, int d)` here.
*/
// Function to return the maximum of four integers
int max_of_four(int a, int b, int c, int d) {
int max = INT_MIN;
if(a > max) {
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 ans = max_of_four(a, b, c, d);
printf("%d", ans);
return 0;
}
Function Definition:
The max_of_four()
function takes four integers and returns the highest value using sequential if
statements. It initializes max
to INT_MIN
to ensure any number entered will be larger.
Header Files:
#include <limits.h>
provides INT_MIN
, a constant representing the lowest possible int
value.
User Input:
The program reads four integers using scanf()
and passes them to the function for evaluation.
Return Value:
The largest value is returned from the function and printed using printf()
.
Modular Design:
Separating logic into a function makes the program more reusable and easier to maintain or extend.