Input numbers and print the largest in C++
if else if - Question 6
In this question, we will see how to input 3 unique integers and print the largest among them in C++ programming using the if else if statement. To know more about if else if statement click on the if else if statement lesson.
Q6) Write a program in C++ to input 3 unique integers and print the largest among them. Make use of logical operator && to solve this question.
Program
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int a,b,c;
cout<<"Enter 3 unique numbers\n";
cin>>a>>b>>c;
if(a==b || b==c || c==a)
{
cout<<"Please enter 3 unique numbers";
}
else if(a>b && a>c)
{
cout<<"Largest number is "<<a;
}
else if(b>a && b>c)
{
cout<<"Largest number is "<<b;
}
else
{
cout<<"Largest number is "<<c;
}
return 0;
}
Output
Enter 3 unique numbers 15 28 7 Largest number is 28