Ask Question

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;

}

+5
Answers (1)
  1. 29 May, 08:15
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers