Write a C++ program to determine the smallest of three numbers by taking user input.


Code:

#include <iostream>


using namespace std;

int main(){
    float x, y, z;

    cout << "Enter the 1st Number: ";
    cin >> x;
    cout << "Enter the 2nd Number: ";
    cin >> y;
    cout << "Enter the 3rd Number: ";
    cin >> z;

    if (x<y && x<z)
        cout << x << " is the smallest number.";
    else if (y<x && y<z)
        cout << y << " is the smallest number.";
    else
        cout << z << " is the smallest number.";
}

Output: 

Enter the 1st Number: 3
Enter the 2nd Number: 4
Enter the 3rd Number: 8
3 is the smallest number.
Process returned 0 (0x0)   execution time : 2.669 s
Press any key to continue.

Previous Post Next Post