In this examples, I’ll show you How to Find Largest Number Among Three Numbers in C++.
In this program, user is asked to enter three numbers.
Then this program finds out the largest number among three numbers entered by user and displays it with proper message.
This program can be used in more than one way.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #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; } if(n2 >= n1 && n2 >= n3) { cout << "Largest number: " << n2; } if(n3 >= n1 && n3 >= n2) { cout << "Largest number: " << n3; } return 0; } |
Output: