In C++ program that inputs three integers and displays the smallest and largest numbers. It should pass the numbers to two functions. A value returning function determines the smallest number and returns it, and a void function determines the largest number and displays it.
Sample run:
Enter three numbers: 9 10 7
The smallest number is:7
The largest number is: 10
#include <iostream> using namespace std; int largest3(int n1, int n2, int n3) { int max = n1; if (n2 > max) { max = n2; } if (n3 > max) { max = n3; } return max; } int smallest3(int n1, int n2, int n3) { int min = n1; if (n2 < min) { min = n2; } if (n3 < min) { min = n3; } return min; } int main() { int n1, n2, n3; cout << "Enter three numbers: "; cin >> n1 >> n2 >> n3; cout << "The smallest number is: " << smallest3(n1, n2, n3) << endl; cout << "The largest number is: " << largest3(n1, n2, n3) << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.