Header Ads Widget

C++ program to find the largest of three numbers using nested if else

 C++ program to find the largest of three numbers using nested if else

Given three numbers , write a program to find the largest among three numbers . 

Sample input

2 5 8

Sample output

8 is largest number

C++ program to find the largest of three numbers using nested if else

The objective of the code is to find the largest among three numbers .

Code(C++):-

#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
cout<<"Enter three numbers \n";
cin>>a>>b>>c;
if(a>b)
{
if(a>c)
cout<<a<<" is the largest number";
else
cout<<c<<" is the largest number";
}
else
{
if(b>c)
cout<<b<<" is the largest number";
else
cout<<c<<" is the largest number";
}
return 0;
}

Output:-

Enter three numbers
2 5 8
8 is the largest number


Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-