Ask Question
1 July, 18:05

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;

}

+4
Answers (1)
  1. 1 July, 21:02
    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?
Find 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 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