Thursday, March 4, 2021
Home C / C++ C++ Program to find largest of 3 numbers

C++ Program to find largest of 3 numbers

In C++ we can implement a logic to write a program to find largest of 3 numbers. So for finding maximum number from given two, three or more numbers, this is just simple, we just need to use the ” if ” conditional statement and use the ” < ” or ” > ” operators to check out the maximum number or minimum number or whatever it is. This is the C++ program to find largest of 3 numbers given:

    // program to find largest of 3 numbers entered by user.
    #include <iostream>
    using namespace std;
    double maximum( double, double, double ); // function prototype
    int main()
        double number1;
        double number2;
        double number3;
        cout << "Enter three floating-point numbers: ";
        cin >> number1 >> number2 >> number3;
        // number1, number2 and number3 are arguments to
        // the maximum function call
        cout << "Maximum is: "
            << maximum( number1, number2, number3 ) << endl;
        return 0;  // indicates successful termination
    double maximum( double x, double y, double z )
        double max = x;
        if ( y > max )    // if y is larger,
            max = y;
        if ( z > max )    // if z is larger,
            max = z;
    return max;       // max is largest value
    } // end function maximum

In the above given code as explained in comments, we are given three numbers of datatype “double” in which we are going to find out the maximum number .Then we passed it to the function which is able to decide the maximum number, in the function we used the ” if ” conditional statement and found the largest of 3 numbers and then returned it to the main().


- Advertisment -

Most Popular

Android Webview Tutorial With Example | How to Use Webview in Android

Android Webview Tutorial With Example Have you seen an Android app displaying Web content using Webview. This Android Webview Tutorial is about integrating Webview using Android Studio....

Student Registration Project in PHP

In this Student Registration Project we are providing a form in simple html to the student and that form sends the data to "student.php"...

Java GUI Calculator Source Code

Here we have a Java GUI Calculator Source Code for you in which a Java GUI calculator has been created using "swing" and "awt". The calculator has...

Numeric Array in PHP

Numeric arrays can store numbers, strings and any object but their index will be represented by numbers. By default array index starts from zero....