C++ Program to find largest of three numbers using parameterized constructor


In this program, You will learn how to find the largest of three numbers using a parameterized constructor in C++.


10 20 30 => 30

40 50 60 => 60


Example: How to find largest of three numbers using parameterized constructor in C++

Run it Now
#include<iostream>
using namespace std;

class Test {
    int c;
public:

    Test(int a, int b, int c) {
        if (a > b && a > c) {
            cout << "\nLargest is : " << a;
        } else if (b > c) {
            cout << "\nLargest is : " << b;
        } else {
            cout << "\nLargest is : " << c;
        }
    }
};

int main() {

    int a, b, c;
    cout << "Enter three numbers : ";
    cin >> a >> b >> c;

    Test obj(a, b, c);

    return 0;
}

Output:

Enter three numbers :400 300 401
Largest is : 401