- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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

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); }

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

Maximum number is: 8

- Related Questions & Answers
- C++ program to find greatest among four input integers
- Find the minimum and maximum values that can be calculated by summing exactly four of the five integers in JavaScript
- Maximum area rectangle by picking four sides from array in C++
- Write a program in C++ to find the maximum and second maximum in a given unsorted array of integers
- C++ find four factors of N with maximum product and sum equal to N .
- Find integers that divides maximum number of elements of the array in C++
- Find maximum XOR of given integer in a stream of integers in C++
- Find four factors of N with maximum product and sum equal to N in C++
- Find a pair with maximum product in array of Integers in C++
- Program to find maximum profit by cutting the rod of different length in C++
- C# program to find the maximum of three numbers
- Program to find maximum number of package that can be bought by buyers in C++
- Find four factors of N with maximum product and sum equal to N - Set-2 in C++
- Find four factors of N with maximum product and sum equal to N - Set-2 in Python Program
- C++ Program to Find Maximum Number of Edge Disjoint Paths

Advertisements