Ask Question
4 December, 14:20

The following statement calls a function named half. The half function returns a value that is half that of the argument. Write the function.

double half (double& number)

{

double half, number;

half = number / 2;

return half;

}

+2
Answers (1)
  1. 4 December, 17:50
    0
    double half (double number) / /to pass by reference is not important here

    {

    double half; / /number again should not be declared here

    half = number / 2;

    return half;

    }

    int main ()

    {

    cout<
    }

    Output:

    25

    Explanation:

    As not mentioned in the question, any data type could have been used like int, float or double. Method half () takes a double variable as parameter which is passed as value as we don't need to make the change at the same address we need value of that argument only. A variable half of double type is declared which will hold the half value. Number is not required to declared again here as it is passed by argument. Then the number is divided by 2 and half is returned.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “The following statement calls a function named half. The half function returns a value that is half that of the argument. Write the ...” 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