ง่าย 0 ข้อที่แก้แล้ว อัตราผ่าน 0%

Rectangle Perimeter

Compute the perimeter of a rectangle from its sides.

โจทย์

A rectangle has two sides of length width and two sides of length height. Its perimeter is the total length of all four sides.

Implement rectangle_perimeter(width, height).

Input

width: The width of the rectangle. height: The height of the rectangle.

Output

Return the perimeter as an integer.

เงื่อนไข

1 ≤ width, height ≤ 1,000,000

ตัวอย่าง

ตัวอย่างที่ 1
อินพุต:
width = 3
height = 5

ผลลัพธ์ที่คาดหวัง:
expected = 16
อินพุต:
long long width = 3;
long long height = 5;

ผลลัพธ์ที่คาดหวัง:
long long expected = 16;
อินพุต:
long width = 3;
long height = 5;

ผลลัพธ์ที่คาดหวัง:
long expected = 16;

คำอธิบาย

Two sides of 3 and two sides of 5: 3 + 3 + 5 + 5 = 16.

ตัวอย่างที่ 2
อินพุต:
width = 7
height = 7

ผลลัพธ์ที่คาดหวัง:
expected = 28
อินพุต:
long long width = 7;
long long height = 7;

ผลลัพธ์ที่คาดหวัง:
long long expected = 28;
อินพุต:
long width = 7;
long height = 7;

ผลลัพธ์ที่คาดหวัง:
long expected = 28;

คำอธิบาย

A square is a rectangle too: 4 × 7 = 28.

แหล่งอ้างอิง

โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน

เรียนรู้จากคนอื่น

แนวทางจากชุมชน

ยังไม่มีวิธีทำที่เผยแพร่ ลองแก้โจทย์นี้เพื่อแชร์วิธีแรก