โจทย์
ดูฉบับแปลReturn n multiplied by itself. The square of a negative number is positive.
Implement square_number(n).
Input
n: Any integer in the allowed range.
Output
Return n × n.
เงื่อนไข
−3,000,000,000 ≤ n ≤ 3,000,000,000, so the square fits a signed 64-bit integer.
ตัวอย่าง
ตัวอย่างที่ 1
อินพุต:
n = 12
ผลลัพธ์ที่คาดหวัง:
expected = 144
อินพุต:
long long n = 12;
ผลลัพธ์ที่คาดหวัง:
long long expected = 144;
อินพุต:
long n = 12;
ผลลัพธ์ที่คาดหวัง:
long expected = 144;
คำอธิบาย
12 × 12 = 144.
ตัวอย่างที่ 2
อินพุต:
n = -7
ผลลัพธ์ที่คาดหวัง:
expected = 49
อินพุต:
long long n = -7;
ผลลัพธ์ที่คาดหวัง:
long long expected = 49;
อินพุต:
long n = -7;
ผลลัพธ์ที่คาดหวัง:
long expected = 49;
คำอธิบาย
(−7) × (−7) = 49.