PLEASE DO IT IN C++ ONLY.
THE MIN-MAX DIGIT PROBLEM
Write a function named minMaxDigit() that accepts an integer as an input parameter and returns the largest and smallest digits using the two output parameters min and max. For example, the call minMaxDigit(68437, min, max) would set min to 3 and max to 8. If there is only one digit, then both min and max are set to the same value. The function has no return statement.
#include <iostream> using namespace std; void minMaxDigit(int n, int &min, int &max); int main() { int min, max, n; cout << "Enter an integer: "; cin >> n; minMaxDigit(n, min, max); cout << "min: " << min << endl; cout << "max: " << max << endl; return 0; } void minMaxDigit(int n, int &min, int &max) { min = n % 10; max = n % 10; int d; if (n < 0) n *= -1; while (n > 0) { d = n % 10; if (d < min) min = d; if (d > max) max = d; n /= 10; } }
Get Answers For Free
Most questions answered within 1 hours.