logo image

C++ program to find largest number from given 3 numbers

34


Following program shows you how to find largest number from given 3 numbers. In this program we get inputs from user and shows largest number from given three numbers using if condition

#include <iostream>

int main() {
	int input1;
	int input2;
	int input3;

	std::cout << "Enter three numbers:\n";
	std::cin >> input1;
	std::cin >> input2;
	std::cin >> input3;

	if ((input1 == input2) && (input1 == input3)) {
		std::cout << "All numbers are equal";

	} else if ((input1 > input2) && (input1 > input3)) {
		std::cout << input1 << "is larger than" << input2 << " and " << input3;

	} else if ((input2 > input1) && (input2 > input3)) {
		std::cout << input2 << " is larger than " << input1 << " and "
				  << input3;

	} else if ((input3 > input1) && (input3 > input2)) {
		std::cout << input3 << " is  larger than " << input2 << " and "
				  << input1;
	}
}

Output:

Example1:

Enter three numbers:
 20
 30
 20
30 is larger than 20 and 20 

Example2:

Enter three numbers:
 2
 2
 2
All numbers are equal