Write the definition of a function signOf, that receives an integer parameter and returns a -1 if the parameter is negative, returns 0 if the parameter is 0 and returns 1 if the parameter is positive. So, if the parameter's value is 7 or 803 or 141 the function returns 1. But if the parameter's value is -22 or -57, the function returns -1. And if the parameter's value is 0, the function returns 0.
.
.
Click on the title for the solution
.
.
.
Click on the title for the solution
.
.
This is the answer:
:
int signOf ( int x ) { if ( x < 0 ) { return - 1; } else if ( x == 0 ) { return 0; } else { return 1; } }
Comments
Post a Comment