i am trying to find the area of given no equilateral triangle. 1st there is a big equilateral triangle with length "l" and from its all sides new equilateral triangle is formed with "l/3" length again from all 3 triangle's free side(i.e only 2 side) new triangle is formed with length "l/9".
so i need to find the total area of all triangles if no of repetition and length is given using recursion
So here the code that i have tried. It gives the correct result for 2 up to repetitions and the wrong result for more:
Module Module1
Dim noOfTriangles As Single = 3 / 2
Function AreaOfTriangle(ByVal noOfRepetition As Integer, ByVal length As Double)
If noOfRepetition = 0 Then
Return Nothing
Else
noOfTriangles = noOfTriangles * 2
Return (((3 ^ (1 / 2)) / 4) * (length ^ 2) + noOfTriangles * AreaOfTriangle(noOfRepetition - 1, length / 3))
End If
End Function
Sub Main()
Dim area As Double
area = AreaOfTriangle(3, 9)
Console.WriteLine(area)
Console.ReadKey()
End Sub
End Module