Cpp program to find middle of three numbers
- Home
- Find elements
- Cpp program to find middle of three numbers
- On
- By
- 0 Comment
- Categories: Find elements
Cpp program to find middle of three numbers
Cpp program to find middle of three numbers
In this tutorial, we will discuss the Cpp program to find middle of three numbers.
This post explains how to find middle number among three numbers using if statements and & operator in C++.
There are many ways to find the middle number of three numbers. but here, we mainly focus on using if statements or if else-if statements and with or without the & operator.
Here, we provide four programs to find the middle number of three numbers.
first two program focus to find a middle number of three integer numbers.
Second two program focus to find a middle number of three floating point numbers in different two methods.

Find the middle number of three integer numbers
Using if statements with the & operator
Program 1
#include#include using namespace std; int main() { int num1,num2,num3; cout<<"Enter three numbers\n"; cin>>num1>>num2>>num3;//takes input from user for three numbers //checking num1 is a middle number or not if(num2>num1 && num1>num3 || num3>num1 && num1>num2){ cout< num2 && num1>num3 || num3>num2 && num2>num1){ cout< num3 && num3>num2 || num2>num3 && num3>num1){ cout< When the above code is executed, it produces the following results
Enter three numbers 27 87 45 45 is a middle numberProgram 2
Using if else – if statements without & operator
#include#include using namespace std; int main() { int num1,num2,num3;//variable declaration cout<<"Enter three numbers for find middle\n"; cin>>num1>>num2>>num3;//Takes input from user if(num1>num2){ if(num2>num3){ cout< num1){ cout< When the above code is executed, it produces the following results
Enter three numbers for find middle 45 12 78 45 is a middle numberFind the middle number of three floating point numbers
Using if statements with the & operator
Program 3
#include#include using namespace std; int main() { float num1,num2,num3; cout<<"Enter three numbers\n"; cin>>num1>>num2>>num3;//takes input from user for num1,num2,num3; //take input numbers from user //checking num1 is a middle number or not if(num2>num1 && num1>num3 || num3>num1 && num1>num2){ cout< num2 && num1>num3 || num3>num2 && num2>num1){ cout< num3 && num3>num2 || num2>num3 && num3>num1){ cout< When the above code is executed, it produces the following results
Enter three numbers 45.34 78.65 23.56 45.34 is a middle numberProgram 4
Using if else – if statements without & operator
#include#include using namespace std; int main() { float num1,num2,num3; cout<<"Enter three numbers for find middle\n"; cin>>num1>>num2>>num3;//takes input from user for numbers num1,num2,num3; if(num1>num2){ if(num2>num3){ cout< num1){ cout< When the above code is executed, it produces the following results
Enter three numbers for find middle 23.54 78.54 45.6 45.6 is a middle numberSuggested for you
C++ Datatypes