Sign of a number · Signo de un número
Sign of a number
Return a number that describes the sign of n: -1 when n is negative, 1 when it is positive, and 0 when it is exactly zero.
Use if to test the cases. The order matters — handle negative and positive first, then return 0 for what is left.
Signo de un número
Devuelve un número que describa el signo de n: -1 cuando n es negativo, 1 cuando es positivo y 0 cuando es exactamente cero.
Utiliza if para probar los casos. El orden importa: maneja primero los negativos y positivos, y luego devuelve 0 para lo restante.
Complete int sign(int n) to return -1 if n is negative, 0 if it is zero, and 1 if it is positive. · Completa int sign(int n) para que devuelva -1 si n es negativo, 0 si es cero, y 1 si es positivo.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.