Calculate values of a function Learn programming with Visual Basic (VB.net) exercises

Lesson:

Basic Data Types


Exercise:

Calculate values of a function 60


Objetive:

Create a Visual Basic (VB.net) program to display certain values of the function y = x2 - 2x + 1 (using integer numbers for x, ranging from -10 to +10)


Code:

Imports System
Public Class exercise56
    Public Shared Sub Main()
        Dim y, x As Integer
        Console.WriteLine("y = x² - 2x +1")
        Console.WriteLine()

        For x = -10 To 10
            y = x * x - 2 * x + 1
            Console.WriteLine("x = {0} ; y=({0})² - 2*({0}) +1 = {1}", x, y)
        Next
    End Sub
End Class