Question

PLEASE DO IT IN C++ ONLY. THE MIN-MAX DIGIT PROBLEM Write a function named minMaxDigit() that...

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.

Homework Answers

Answer #1
#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;
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report the total number of words (as an integer) and the average word length (as an un-rounded number). For example, suppose the file tobe.txt contains the following text: To be or not to be, that is the...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) For this exercise you should be able to write a logical expression (i.e., with logical operators) which checks if some integer x consists of exactly 5 digits. Ex: 30498 and -14004 are 5-digit numbers, while 1018, -2 and 46 are not. Complete the intQ2(intQ2_input) function that takes an input integer parameter and returns 1 if the number is...
In Python: Problem 4. Write a program [call it minmax.py] that accepts three integers in the...
In Python: Problem 4. Write a program [call it minmax.py] that accepts three integers in the range [0-100] as input from the user. Your program should then determine and print the smallest and largest integers in the values entered by the user using comparison operators *not* using predefined min or max Python functions. For instance: If the user input is: 36 5 99 your program should give as output: min = 5 max = 99 If the user input is:...
USING PYTHON do all the he problems using while loop , continue and break 1-This problem...
USING PYTHON do all the he problems using while loop , continue and break 1-This problem provides practice using a while True loop.write a function named twoWords that gets and returns two words from a user. The first word is of a specified length, and the second word begins with a specified letter.The function twoWords takes two parameters: an integer, length, that is the length of the first word and a character, firstLetter, that is the first letter of the...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to N. The function calculateSum has one parameter N of type integer and returns an integer which represents the sum from -1 to N, inclusive. Write another function calculateAverage that calculates an average. This function will have two parameters: the sum and the number of items. It returns the average (of type float). The main function should be responsible for all inputs and outputs. Your...
Programming in C language (not C++) Write a main function with a function call to a...
Programming in C language (not C++) Write a main function with a function call to a function called Calculation which has two integer arguments/ parameters. The function returns a character. Declare and initialize the necessary data variables and assign balues needed to make it executable and to prevent loss of information. //input 2 integer values //returns the characterequivalent of the higher of the two integer values char Calculation(int, int);
Write a algorthim only by using while loop That uses a function, reverseDigit. The function takes...
Write a algorthim only by using while loop That uses a function, reverseDigit. The function takes an integer as a parameter and returns the number with its digits reversed. For example, the value ofreverseDigit(12345) is 54321; the value of reverseDigit(5600) is 65; the value of reverseDigit(7008) is 8007; and the value of reverseDigit(-532) is -235.
Using C++ Write a template function that accepts an integer parameter and returns its integer square...
Using C++ Write a template function that accepts an integer parameter and returns its integer square root. The function should return -1, if the argument passed is not integer. Demonstrate the function with a suitable driver program .
Use C++ to implement the following program about Prime Factorization of a Number. Do BOTH parts...
Use C++ to implement the following program about Prime Factorization of a Number. Do BOTH parts of the problem or you will lose points. Provide comments to explain each step. a. Write a function that takes as a parameter a positive integer and returns a list (array) of the prime factors of the given integer. For example, if the parameter is 20, you should return 2 2 5. b. Write a function that tests the above function by asking the...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: a) Complete the int Q7a(intQ7_input) function takes a seven-digit positive integer as input and returns it reversed. For example, if the integer is 9806593, the program should print 3956089. You are not permitted to use any function of C standard library other than scanf()and printf().You are not permitted to use...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT