Trusted answers to developer questions

okwudili onyejiaku

The total space occupied by a rectangle is known as its **area**. This area, on the other hand, is the product of its length and breadth. The length refers to the longest side, while the breadth refers to the shorter side. In Ruby, we can calculate the area of a rectangle.

area = length * breadth

An equation to calculate the area of a rectangle

`length`

: This is the length of the rectangle.

`breadth`

: This is the breadth of the rectangle.

The value returned is the area of the rectangle.

# create some lengths length1 = 23 length2 = 4.5 length3 = 50 # create some breadths breadth1 = 3.5 breadth2 = 0.5 breadth3 = 12 # print the areas puts length1 * breadth1 puts length2 * breadth2 puts length3 * breadth3

Get the area of the rectangle in Ruby

- Lines 2–4: We declare and initialize the lengths of the rectangles.
- Lines 7–9: We declare and initialize the breadths of the rectangles.
- Lines 12–14: We print the products of the lengths and breadths.

RELATED TAGS

ruby

communitycreator

CONTRIBUTOR

okwudili onyejiaku

RELATED COURSES

View all Courses

Keep Exploring

Related Courses