C++ Program to Find Largest of Two Numbers

In this section you will learn how to find whether a number is greater or small in c++. We will use if else condition to check the greater or smaller number and we will show the result on output screen. In this program we are taking the input from user.

Let’s suppose a user will input two numbers as '26' and '20' then as result it will show 26 is greater and 20 is smaller.

How program will work?

C++ Program to Find Largest of Two Numbers


	#include<iostream.h>
	#include<conio.h>

	//GREATER & SMALLER NUMBER PROGRAM
	void main()
	{
		int a,b;
		cout<<"ENTER THE FIRST NUMBER:- ";
		cin>>a;
		cout<<"\nENTER THE SECOND NUMBER:- ";
		cin>>b;
		if(a>b)
		{
			cout<<a<<" NUMBER IS LARGEST "<<b<<" NUMBER IS SMALLEST.";
		}
		else
		{
			cout<<b<<" NUMBER IS LARGEST "<<a<<" NUMBER IS SMALLEST.";
		}

	getch();
	}

Output:


	ENTER THE FIRST NUMBER:- 26
	ENTER THE SECOND NUMBER:- 20
	26 NUMBER IS LARGEST AND 20 IS SMALLEST.

Post Your Comment