Two dimensional array 2: circunference on screen Learn programming Visual Basic (


Arrays, Structures and Strings


Two dimensional array 2: circunference on screen


Create a Visual Basic ( program that declares creates a 70x20 two-dimensional array of characters, "draws" a circumference or radius 8 inside it, and displays it on screen.

Hint: the points in the circumference can be obtained using:
x = xCenter + r * cos angle
y = yCenter + r * sin angle

"sin" and "cos" expect the angle to be measured in radians, instead of degrees. To convert from one unit to the other, you must remember that 360 degrees = 2 PI radians (or 180 degrees = PI radians): float radians = (angle * Math.PI / 180.0);

You might draw 72 points (as there are 360 degrees in a circumference, they would be spaced 5 degreees from each other)

Hint: in Visual Basic (, cosine is Math.Cos, sine is Math.Sin and PI is Math.PI


Imports System
Public Class exercise93
    Public Shared Sub Main()
        Dim r, x, y As Double

        For i As Integer = 0 To 360 - 1 Step 5
            rad = i * Math.PI / 180.0
            x = 35 + 8 * Math.Cos(rad)
            y = 10 + 8 * Math.Sin(rad)
            Console.SetCursorPosition(CInt(x), CInt(y))

        Console.SetCursorPosition(1, 20)
    End Sub
End Class

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.