Option Strict On
Module Module1
    Function f(ByVal x As Double) As Double
        Return 1 / x
    End Function
    Sub Main()
        Dim a, b, h, y, s1, s2, s3, s4, x, p, sum2, sum1 As Double
        Dim n As Integer

        Console.WriteLine("Число элементарных отрезков?")
        Console.WriteLine()

        n = Integer.Parse(Console.ReadLine)
        b = 1.5
        a = 0.5
        h = (b - a) / n
        y = 0
        sum2 = 0
        sum1 = 0
        For i As Integer = 1 To CInt(n - 1)
            x = a + i * h
            y = y + f(x)
            If i Mod 2 = 0 Then
                sum2 = sum2 + f(x)
            Else
                sum1 = sum1 + f(x)
            End If
        Next i
        p = Math.Log(b) - Math.Log(a)
        s1 = h * (y + f(a))
        s2 = h * (y + f(b))
        s3 = h * ((f(a) + f(b)) / 2 + y)
        s4 = h / 3 * (f(a) + f(b) + 2 * sum2 + 4 * sum1)
        Console.WriteLine()
        Console.WriteLine()
        Console.WriteLine()
        Console.WriteLine("Метод             Интеграл        Ошибка вычисления")
        Console.WriteLine("Прямоуг. лев.     {0:f6}           {1:E6}", s1, p - s1)
        Console.WriteLine("Прямоуг. прав.    {0:f6}           {1,14:E6}", s2, p - s2)
        Console.WriteLine("Трапеции          {0:f6}           {1:E6}", s3, p - s3)
        Console.WriteLine("Парабол           {0:f6}           {1,14:E6}", s4, p - s4)
        Console.ReadLine()


    End Sub

End Module

