Sign of a number · סימן של מספר
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. · שלים את int sign(int n) כדי להחזיר -1 אם n שלילי, 0 אם הוא אפס, ו1 אם הוא חיובי.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.