Ask Question
28 October, 02:01

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.

+1
Answers (1)
  1. 28 October, 05:56
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers