25.5k views
5 votes
Write the definition of a function half , which receives an integer parameter and returns an integer that is half the value of the parameter. (Use integer division!) So if the parameter's value is 7, the function returns the value 3. If the parameter's value happens to be 44, the functions returns the value 22.

1 Answer

4 votes

Answer:

The answer to this question can be given as:

Function definition:

int half(int value)

//function name half with an integer parameter

{

return value/2; //return integer division.

}

Explanation:

In the above function definition, we define a function that is half. This function returns a value that is an integer. In this function, we pass an integer variable that is value. In this function, we return the value of the parameter in the integer division. for example, if the user passes the value 7 in the function parameter so the function will return 3 because we will return an integer value, not floating-point value.

User LeSam
by
7.2k points