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. · คลิก Run เพื่อดูผลลัพธ์ที่นี่