C++ Online Compiler
Example: Find Largest Number Among Three in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Find Largest Number Among Three #include <iostream> // Required for input/output operations using namespace std; // Use standard namespace int main() { // Step 1: Declare three integer variables to store the numbers int num1, num2, num3; // Step 2: Prompt the user to enter three numbers cout << "Enter three numbers: "; // Step 3: Read the three numbers from the user cin >> num1 >> num2 >> num3; // Step 4: Use if-else if-else to find the largest number if (num1 >= num2 && num1 >= num3) { // If num1 is greater than or equal to both num2 and num3, then num1 is the largest cout << "The largest number is: " << num1 << endl; } else if (num2 >= num1 && num2 >= num3) { // If num2 is greater than or equal to both num1 and num3, then num2 is the largest cout << "The largest number is: " << num2 << endl; } else { // If neither num1 nor num2 is the largest, then num3 must be the largest cout << "The largest number is: " << num3 << endl; } return 0; // Indicate successful program execution }
Output
Clear
ADVERTISEMENTS