Skip to content · ⁨ข้ามไปยังเนื้อหา⁩

Sign of a number · ⁨เครื่องหมายของตัวเลข⁩

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 สำหรับสิ่งที่เหลือ

Log in or create account · ⁨เข้าสู่ระบบหรือสร้างบัญชี⁩

IGCSE, A-Level & AP