Option Strict On
Module Module1
    Function f(ByVal x As Double) As Double
        Return 1 / x
    End Function
    Sub Main()
        Console.WriteLine("Число элементарных отрезков?")
        Dim otr As Integer = Integer.Parse(Console.ReadLine)
        Dim ist_znach, a, b, dx, slag, slagpar, sumlev, sumprav, sumtrap, sumpar As Double
        ist_znach = Math.Log(1.5) - Math.Log(0.5)
        a = 0.5
        b = 1.5
        dx = (b - a) / otr
        For i As Integer = 1 To otr - 1
            slag = f(a + i * dx) * dx
            sumlev = sumlev + slag
            If (-1) ^ i > 0 Then
                slagpar = dx / 3 * 2 * f(a + i * dx)
            Else
                slagpar = dx / 3 * 4 * f(a + i * dx)
            End If
            sumpar = sumpar + slagpar
        Next i
        sumprav = sumlev + f(b) * dx
        sumtrap = sumlev + (f(a) + f(b)) * dx / 2
        sumlev = sumlev + f(a) * dx
        sumpar = sumpar + (f(a) + f(b)) * dx / 3
        Console.WriteLine()
        Console.WriteLine("Метод            Интеграл       Ошибка вычислений")
        Console.WriteLine("прямоуг.лев.     {0:F6}{1,20:E6}", sumlev, (ist_znach - sumlev))
        Console.WriteLine("прямоуг.прав.    {0:F6}{1,20:E6}", sumprav, (ist_znach - sumprav))
        Console.WriteLine("трапеций         {0:F6}{1,20:E6}", sumtrap, (ist_znach - sumtrap))
        Console.WriteLine("парабол          {0:F6}{1,20:E6}", sumpar, (ist_znach - sumpar))
        Console.ReadLine()

    End Sub

End Module
