Sign of a number · Sinal de um 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.
Sinal de um número
Retorne um número que descreva o sinal de n: -1 quando n for negativo, 1 quando for positivo e 0 quando for exatamente zero.
Use if para testar os casos. A ordem importa — trate negativos e positivos primeiro, depois retorne 0 para o restante.
Complete int sign(int n) to return -1 if · se n is negative, 0 if it is zero, and 1 if it is positive. · Complete int sign(int n) para retornar -1 se n for negativo, 0 se for zero, e 1 se for positivo.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.