Programs

C++ Program to Find Largest Number Among Three Numbers

C++ Program to Find Largest Number Among Three Numbers

To find the largest number among three numbers, you can use conditional statements (if, else if, else) to compare the numbers and determine which one is the largest. Below is a Turbo C++ program that demonstrates this:

#include <iostream.h>
#include <conio.h>

void main() {
    clrscr();  // Clear the screen (specific to Turbo C++)

    float num1, num2, num3;

    // Taking input from the user
    cout << "Enter first number: ";
    cin >> num1;

    cout << "Enter second number: ";
    cin >> num2;

    cout << "Enter third number: ";
    cin >> num3;

    // Checking for the largest number
    if (num1 >= num2 && num1 >= num3) {
        cout << "The largest number is: " << num1 << endl;
    } else if (num2 >= num1 && num2 >= num3) {
        cout << "The largest number is: " << num2 << endl;
    } else {
        cout << "The largest number is: " << num3 << endl;
    }

    getch();  // Wait for user input (specific to Turbo C++)
}

To compile and run this program in Turbo C++:

  1. Open Turbo C++.
  2. Create a new file and copy-paste the above code into it.
  3. Save the file.
  4. Compile the code (usually by pressing Alt + F9).
  5. Run the program (usually by pressing Ctrl + F9).

The program will prompt you to enter three numbers and then it will display the largest among them.