The smallest element from three

To find the smallest element from three numbers in C++, you can follow these steps:

  1. Declare three variables to hold the three numbers: num1, num2, and num3.
  2. Prompt the user to enter the first number and store it in num1.
  3. Prompt the user to enter the second number and store it in num2.
  4. Prompt the user to enter the third number and store it in num3.
  5. Compare num1 with num2 using an if statement. If num1 is smaller than num2, compare it with num3. If num1 is smaller than num3, then num1 is the smallest number.
  6. If num1 is not the smallest number, compare num2 with num3. If num2 is smaller than num3, then num2 is the smallest number.
  7. If none of the above conditions are true, then num3 is the smallest number.
  8. Print the smallest number to the console.

Here is an example implementation of the above steps:

#include <iostream>
using namespace std;

int main() {
    int num1, num2, num3;

    cout << "Enter the first number: ";
    cin >> num1;

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

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

    if (num1 < num2) {
        if (num1 < num3) {
            cout << "The smallest number is: " << num1 << endl;
        } else {
            cout << "The smallest number is: " << num3 << endl;
        }
    } else {
        if (num2 < num3) {
            cout << "The smallest number is: " << num2 << endl;
        } else {
            cout << "The smallest number is: " << num3 << endl;
        }
    }

    return 0;
}

This program prompts the user to enter three numbers and then compares them to determine the smallest number. The if-else statements are used to handle the comparisons and print the result to the console.