Skip to content

#006 Area of a Triangle

Adam Kubiś edited this page Mar 30, 2025 · 2 revisions

Published by EstoniaAndEnglish

geometry math numbers

Write a function that takes the base and height of a triangle and return its area.

triArea(3, 2) ➞ 3

triArea(7, 4) ➞ 14

triArea(10, 10) ➞ 50

Notes

  • The area of a triangle is: (base * height) / 2

  • Don't forget to return the result.

Complexity

O(1), function performs a fixed number of arithmetic operations—multiplying the base and height, and then dividing by 2. This results in constant time and constant space usage.

This means that the execution time and memory usage remain the same regardless of the input size.

flowchart

Clone this wiki locally