C++ program to find the smallest of two numbers

In this example, you will learn a c++ program to find the smallest value between two numbers. This program takes to numbers from the user and displays the smallest value. If the user enters 4 and 7 programs find the smallest from both which is 4.


To understand this program perfectly, you should have the following C++ programming knowledge.

Program: Find the Smallest of Two Numbers

// C++ program to find smallest of two numbers
using namespace std;

int main()
int number1, number2, smallest ;
cout<<"Enter first number: ";
cout<<"Enter second number: ";
cout<<"Smallest of the two number is: "<<smallest;
return 0;


Enter first number: 4
Enter second number: 7
Smallest of the two number is: 4

Description and working of this program

  • Take two numbers from the user and store them in “number1” and “number2”.
  • Condition if the first number is smaller than the second than smallest= number1
  • If the above condition is not true then smallest = number2
  • Print smallest on the screen.