how to make a function for the area of a triangle in R the program?

444 Views Asked by At

If a, b and c are the lengths of the sides of a triangle, then the area is given by $\sqrt(s(s − a)(s − b)(s − c))$, where s = $\frac{1}{2}$( a + b + c). a) Write a function called triangle which takes as input a, b and c and returns the area of a triangle.

If tried to put this into r-studio so far:

--

area_triangle <- function (a,b,c) {area <- sqrt[s(s − a)(s − b)(s − c)] s=.5*(a+b+c) return(area)}

area_triangle(1,3,5)

--

but it keeps giving errors. if someone can please exlpain.