Microsoft Small Basic

Program Listing: QCD342-0

' for any polygon, the area is / para cualquier polígono, el área es
' (nl^2)/(4 tan(360/2n) )
' where / donde
' l=length of side / longitud del lado
' n=number of sides / numero de lados
' This is also a solution to the ArcTan, since Tan(x) = Tan(x+pi).

TextWindow.WriteLine("number of sides / numero de lados: ")
n = TextWindow.ReadNumber()

TextWindow.WriteLine("length of side / longitud del lado: ")
l = TextWindow.ReadNumber()
lcuad = Math.Power(l, 2)

dividendo = n * lcuad
TextWindow.WriteLine("the dividend is / el dividendo es : " + dividendo)


angulo = (360/ (2* n) + Math.Pi)
TextWindow.WriteLine( "the angle is / el angulo es: " + angulo)
tangente = Math.Tan(angulo)
TextWindow.WriteLine(" tangent in radians / la tang en radianes es: " + tangente)
divisor = 4 * tangente
TextWindow.WriteLine( "the divisor is / el divisor es: " + divisor)
If divisor < 0 Then
divisor = divisor * (-1)
Else
EndIf
Area = dividendo / divisor
TextWindow.WriteLine( " the erea is / el area es: " + Area)

TextWindow.WriteLine("")
TextWindow.WriteLine("n = " + n)
TextWindow.WriteLine("l = " + l)
a = Math.Pi / n
TextWindow.WriteLine("a = Pi/n = " + a + " (" + (a * 180 / Math.Pi) + " deg)")
r = l / (2 * Math.Sin(a))
TextWindow.WriteLine("r = l/(2 sin a) = " + r)
Area = n * l * r * Math.Cos(a) / 2
TextWindow.WriteLine("A = (nlr cos a)/2 = " + Area)

GraphicsWindow.BackgroundColor= "Yellow"
GraphicsWindow.PenColor = "Black"
angulo = 360 / n

For i = 1 To n
Turtle.Move(l)
Turtle.Turn(angulo)
EndFor