C++

# C++ program to find the smallest number of the three number using if statement

## Learn how to find the smallest number of the three number in C++ language using if statement and more:

In this article, you’ll learn to find the smallest number of the three number in details with example and explanation in C++ language without giving input from the keyboard or giving input from the keyboard.

Recommended for you:

### Q: What is the purpose of this program

Ans: We create a program in C++ language that helps us to find the smallest among the three number without giving input from the keyboard or giving input from the keyboard.

There are many processes to find the smallest among the three number some are below given:

• Using if statement
• Using if…else statement
• Using Nested if…else statement

Here, we find the smallest number of the three number by using if statement.

### Explanation:

• First, create three variable here we create num1, num2, num3 for storing three number then
• Check num1 with num2 and num1 with num3
• If num1 is smaller than num2 and num3, then print on the screen the value of num1 and check the next statement.
• Check num2 with num3 and num2 with num1
• If num2 is smaller than num3 and num1, then print on the screen the value of num2 and check the next statement.
• Check num3 with num1 and num3 with num2
• If num3 is smaller than num1 and num2, then print on the screen the value of num3 and stop checking and print on the screen which is greater among three number.

Q: Write a program in C++ to find smallest among three number

Solution:

 #include #include using namespace std; int main() { int num1=41,num2=44,num3=46; if(num1<=num2 && num1<=num3) { cout<<“smallest number is ” <

 The output of this program: smallest number is 41

Q: Write a program in C++ to find smallest among three number, input is given by user

Solution:

 #include #include using namespace std; int main() { int num1, num2, num3; cout<<“Enter three number: “; cin>> num1>>num2>>num3; if(num1>=num2 && num1>=num3) { cout<<“Largest number is ” <=num3 && num2>=num1) { cout<< “Largest number is ” <=num1 && num3>=num2) { cout<<“Largest number is “<

 The output of this program: Enter three number: 58 54 50 smallest number is 50

Note: In the above two program supports only integer value if enter a real value like 2.2, 4.5, 8.6 then it will not show the result. To show the result we declare the variable with a float in place of int. Exanple are given below:

Q: Write a program in C++ to find smallest among three number

Solution:

 #include #include using namespace std; int main() { float num1=41.258,num2=41.145,num3=41.564; if(num1<=num2 && num1<=num3) { cout<<“smallest number is ” <

 The Output of this program: smallest number is 41.145

Q: Write a program in C++ to find smallest among three number, input is given by user

Solution:

 #include #include using namespace std; int main() { float num1=41,num2=44,num3=46; cout<<“Enter three number: “; cin>> num1>>num2>>num3; if(num1<=num2 && num1<=num3) { cout<<“smallest number is ” <
 The output of this program: Enter three number: 55.235 55.258 55.894 smallest number is 55.235