Showing posts with label Write a program to find the greatest of three numbers. Show all posts
Showing posts with label Write a program to find the greatest of three numbers. Show all posts

## C++ Program to Find The Largest Number Among Three Numbers.

You must have basic knowledge of  C++ programming language and variable  , while loop and if..ealse and for loop

### In this programe,you will fimd the largest number between three numbers using if ,if else ,nested if else statement.

In this program,enter three values by user.
This program used more than one way.

## Example1:Find Largest Number Using if Statement

#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
int num1, num2,num3;

cout << "Plz Enter three numbers";
cin >> num1;
cin >>num2;
cin >>num3;

if(num1>=  num2 &&  num1 >=num3)
{
cout <<  "The greatest number is :"<<n2;
}
if(num2>=  num1 &&  num2 >=num3)
{
cout << "The greatest number is :"<<num2;
}

if(num3>=  num1 &&  num3 >=num2)
{
cout << "The greatest number is :"<<num3;
}

return 0;
getch();
}

output
----------------------------------------------
Plz Enter three number
5
8
9
The greatest number is:9

## Example2:Find Largest Number Using if,else statement

#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
int num1, num2,num3;

cout << "Plz Enter three numbers";
cin >> num1>>num2 >>num3;

if((num1>=num2) && (num1>=num3))
cout << "The greatest number is:<<num1;
else if((num2 >= num2) && (num2 >= num3)
cout << "The greatest number is:<<num2;
else
cout << "The greatest number is:<<num3;

return 0;
getch();
}

output
----------------------------
Plz Enter three number
5
8
9
The greatest number is:9

## Example3:Find Largest Number Using nested if..else statement

#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
int num1, num2,num3;

cout << "Plz Enter three numbers";
cin >> num1>>num2 >>num3;

if(num1>=num2)
{
if(num1>=num3)
cout << "The greatest number is:<<num1;
else
cout << "The greatest number is:<<num3;
}
else
{
if(num2 >= num3)

cout << "The greatest number is:<<num2;
else
cout << "The greatest number is:<<num3;

}
return 0;
getch();
}

output
----------------------------
Plz Enter three number
5
8
9
The greatest number is:9