Sign of a number
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
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.
日本語
符号
n の符号を表す数字を返してください:-1 は n が負のとき、1 は正のとき、0 はちょうどゼロのとき。
if を使ってケースを試してください。順序が重要です——まず負と正を処理し、残りの分に対して 0 を返します。
Complete int sign(int n) to return -1 if n is negative, 0 if it is zero, and 1 if it is positive.
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。