C++ program to Find Largest of three numbers using nested if

By | 25.12.2016

Largest of three numbers using nested if


Write a C++ program to Find Largest of three numbers using nested if. Here’s simple program to Find Largest of three numbers using nested if in C++ Programming Language.


Here is source code of the C++ program to Find Largest of three numbers using nested if. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.


SOURCE CODE : :


/*  C++ program to Find Largest of three numbers using nested if  */

#include<iostream>
using namespace std;

int main()
{

    int a, b, c;
    cout <<"Enter 1st number :: ";
    cin>>a;
    cout <<"\nEnter 2nd number :: ";
    cin>>b;
    cout <<"\nEnter 3rd number :: ";
    cin>>c;

    if(a>=b && a>=c)
    {
    cout<<"\nThe Largest number among [ "<<a<<", "<<b<<", "<<c<<" ] is :: "<<a<<"\n";
    }
    if(b>=a && b>=c)
    {
    cout<<"\nThe Largest number among [ "<<a<<", "<<b<<", "<<c<<" ] is :: "<<b<<"\n";
    }
    if(c>=a && c>=b)
    {
    cout<<"\nThe Largest number among [ "<<a<<", "<<b<<", "<<c<<" ] is :: "<<c<<"\n";
    }

   return 0;
}

Output : :


/*  C++ program to Find Largest of three numbers using nested if  */

Enter 1st number :: 5

Enter 2nd number :: 2

Enter 3rd number :: 7

The Largest number among [ 5, 2, 7 ] is :: 7

Process returned 0

Above is the source code for C++ program to Find Largest of three number using nested if which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

4 2 votes
Article Rating
Subscribe
Notify of
guest

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
wajeeha batool

Problem”c++ program to find the largest number among three numbers”
a more easy and quick way to do it is:
#include<iostream>
#include <cmath>
using namespace std;
int main(){

float a;
float b;
float c;

cout<<“enter first number of your choice”<<endl;
 cin>>a; 
 cout<<“enter second number of your choice”<<endl;
 cin>>b;
 cout<<“enter third number of your choice”<<endl;
 cin>>c;

  cout<<fmax(c,(fmax(a,b)))<<” is the greatest number”<<endl;

return 0;
}

Dicam

#include<iostream>
using namespace std;

int main()
{
int n1,n2,n3,max;
cout<<“Enter three numbers\n”;
cin>>n1>>n2>>n3;
max=n1;
if(n2>max)
max=n2;

if(n3>max)
max=n3;

cout<<max<<” is the largest number\n”;

system(“pause”);
return 0;
}

Last edited 2 years ago by Dicam
cel

When we write the code like this there exist a problem. If you try a=3 b=3 and c=1 output will be 2 of 3 ( a and b). So we should write else if except first condition. #include<iostream> using namespace std; int main() { int x, y, z; cout << “enter 3 numbers: “; cin >> x >> y >> z; if (x >= y && x >= z) { cout << x << ” is the largest number.”; } else if (y >= x && y >= z) { cout << y << ” is the largest number.”; }… Read more »