Suppose we have four integers a, b, c and d. We shall have to find the greatest number 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 = 75, b = 18, c = 25, d = 98, then the output will be 98.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
#include <iostream> using namespace std; int max(int x, int y){ if(x > y){ return x; }else{ return y; } } int main(){ int a = 75, b = 18, c = 25, d = 98; int left_max = max(a, b); int right_max = max(c, d); int final_max = max(left_max, right_max); cout << final_max; }
75, 18, 25, 98
98