Program To Find Maximum Among 3 Numbers in C++:
There are various ways to find the maximum among 3 numbers. Some of the Algorithms are given below:
Algorithm 1:
Step 1: Accept three numbers say A, B&C.
Step 2:
If A>B & A>C then Display A is greatest
else if B>C then Display B is greatest
else Display C is greatest
Step 3: Stop
Algorithm 2:
Step 1: Accept three numbers say A, B&C.
Step 2:
If A>B & A>C then Display A is greatest
else if B>A&B>C then Display B is greatest
else Display C is greatest
Step 3: Stop
Algorithm 3:
Step 1: Accept three numbers say A, B&C.
Step 2:
If A>B
then check If A>C then Display A is greatest else Display C is greatest
else
check If B>C then Display B is greatest else Display C is greatest
Step 3: Stop
The above Algorithms can be implemented in C++ as follows:
Code 1:
Code 2:
Code 3:
There is an alternate for using if-else statements in C++ which is a ternary operator. So we can make a program by using the ternary operator also. Following is the example of a ternary operator program in C++ to find maximum between three numbers.
0 Comments