Find Max Number Among the Given Three Number Using If/Else Statements

  • November 11, 2022
  • C++
Accessing Elements
  • n1 is compared to n2. If n1 is larger than n2, it is compared to n3. If it is greater than n3 as well, n1 is the max number; otherwise, n3 is the max number.
  • If n1 is not greater than n2, it follows that n2 is greater than n1. After that, n2 is compared to n3. If it is greater than n3, n2 is the largest number; otherwise, n3 is the largest number.

Program code:

#include <iostream>
using namespace std;

int main() {
    float n1, n2, n3;

    cout << "Enter three numbers: ";
    cin >> n1 >> n2 >> n3;

    if((n1 >= n2) && (n1 >= n3))
        cout << "Largest number: " << n1;
    else if ((n2 >= n1) && (n2 >= n3))
        cout << "Largest number: " << n2;
        cout << "Largest number: " << n3;
    return 0;
Enter three numbers: 55 67 43
Largest number: 67

Note: also read about Check for Prime number

Follow Me

Please follow me to read my latest post on programming and technology if you like my post.

Leave a Reply

Your email address will not be published. Required fields are marked *