Answer to Question #289430 in C++ for Josh Matusenos

Question #289430

Write a C++ program using a function to identify the smallest number from three numbers. Name the function as minval.



Sample Output:



Enter First Number: 300

Enter Second Number: 200

Enter Third Number: 1000



The Smallest Number: 200


1
Expert's answer
2022-01-21T09:28:45-0500
#include <iostream>
using namespace std;

int minval(int x, int y, int z) {
    if (x < y && x < z) {
        return x;
    }
    if (y < x && y < z) {
        return y;
    }
    return z;
}

int main() {
    int x1, x2, x3;

    cout << "Enter First Number: ";
    cin >> x1;
    cout << "Enter Second Number: ";
    cin >> x2;
    cout << "Enter Third Number: ";
    cin >> x3;
    cout << endl;

    cout << "The Smallest Number: " << minval(x1, x2, x3);

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog