Largest number in C++


Q.Write a C++ program to find the largest number among three number using simple if statement ?

#include <iostream>    
using namespace std;
  
int main()
{ 
    int n1, n2, n3;
    cout << "Enter the three different numbers: ";
    cin >> n1 >> n2 >> n3;
    if( n1>n2 && n1>n3 )
    {
        cout << n1 << " is the largest number.";
    }
    if( n2>n1 && n2>n3 )
    {
        cout << n2 << "is the largest number.";
    }
    if( n3>n1 && n3>n2 )
    {
        cout << n3 << " is the largest number.";
    }
	return 0;    
} 

Q. Write an algorithm to find the largest number among three number using simple if statement ?

1. Start
2. Prompt the user to enter three different numbers.
3. Read the inputs `n1`, `n2`, and `n3`.
4. Compare the first number (`n1`) with the second (`n2`) and the third (`n3`):
    - If `n1` is greater than both `n2` and `n3`, then `n1` is the largest number.
5. Else, compare the second number (`n2`) with the first (`n1`) and the third (`n3`):
    - If `n2` is greater than both `n1` and `n3`, then `n2` is the largest number.
6. Else, compare the third number (`n3`) with the first (`n1`) and the second (`n2`):
    - If `n3` is greater than both `n1` and `n2`, then `n3` is the largest number.
7. Display the largest number.
8. End 



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.