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. · اضغط تشغيل لرؤية المخرجات هنا.