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.
s <- (a+b+c)/2, thenarea <- sqrt(s*(s-a)*(s-b)*(s-b)), and finallyreturn(area). – azif00 Jan 27 '22 at 18:25