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
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
RELATED TAGS
CONTRIBUTOR
View all Courses