Ask Question
15 January, 13:04

Write the definition of a function absoluteValue, that receives an integer parameter and returns the absolute value of the parameter's value. (You should write the logic for absolute value yourself ... do not use the abs function of the C library.) So, if the parameter's value is 7 or 803 or 141 the function returns 7, 803 or 141 respectively. But if the parameter's value is - 22 or - 57, the function returns 22 or 57 (same magnitude but a positive instead of a negative). And if the parameter's value is 0, the function returns 0.

+2
Answers (1)
  1. 15 January, 14:44
    0
    int absoluteValue (int number) {

    if (number < 0)

    number = number * (-1);

    else if (number > 0)

    number = number;

    else

    number = 0;

    return number;

    }

    Explanation:

    Create a function called absoluteValue that takes an integer parameter, number

    Check if the number is smaller than 0. If it is, multiply the number with - 1

    Check if the number is greater than 0. If it is, assign it to itself

    Check if the number is 0. If it is, assign it to 0

    Return the number
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write the definition of a function absoluteValue, that receives an integer parameter and returns the absolute value of the parameter's ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers