# C program to find maximum of four integers by defining function

CServer Side ProgrammingProgramming

#### C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

#### Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

#### Master C and Embedded C Programming- Learn as you go

Best Seller

66 Lectures 5.5 hours

Suppose we have four numbers a, b, c and d. We shall have to find maximum among them by making our own function. So we shall create one max() function that takes two numbers as input and finds the maximum, then using them we shall find maximum of all four numbers.

So, if the input is like a = 5, b = 8, c = 2, d = 3, then the output will be 8

To solve this, we will follow these steps −

• define a function max(), this will take x and y

• return maximum of x and y

• take four numbers a, b, c and d

• left_max := max(a, b)

• right_max := max(c, d)

• final_max = max(left_max, right_max)

• return final_max

## Example

Let us see the following implementation to get better understanding −

#include <stdio.h>
int max(int x, int y){
if(x > y){
return x;
}else{
return y;
}
}
int main(){
int a = 5, b = 8, c = 2, d = 3;
int left_max = max(a, b);
int right_max = max(c, d);
int final_max = max(left_max, right_max);
printf("Maximum number is: %d", final_max);
}


## Input

a = 5, b = 8, c = 2, d = 3

## Output

Maximum number is: 8
Updated on 08-Oct-2021 10:53:33