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
#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;
}
Comments
Leave a comment