Option Strict On
Module Module1
    Function diff(ByVal x As Double, ByVal y As Double) As Double
        Return Math.Cos(x) + Math.Sin(y)
    End Function
    Sub Main()
        Dim x, yn, y2n, y As Double
        yn = 0
        y = 0
        Dim h As Double = 0.25
        Dim eps As Double = 0.001
        Dim xmin As Double = 2.5
        Dim xmax As Double = 4
        Dim n As Integer = 1
        Console.WriteLine(" x       y       y'         h/2n         2n")
        Console.WriteLine(" ------------------------------------------------")
        Console.WriteLine(" {0:f}    {1:f4}    {2:e1}", xmin, yn, diff(x, yn))
        For i As Integer = 0 To CInt((xmax - xmin) / h) - 1
            x = xmin + i * h
            yn = y
            y2n = y
            Do
                For j As Integer = 1 To n
                    yn = yn + h / n * diff(x, yn)
                    x += h / n
                Next j
                x = xmin + i * h
                For j As Integer = 1 To 2 * n
                    y2n = y2n + h / (2 * n) * diff(x, y2n)
                    x += h / 2 / n
                Next j
                n *= 2
            Loop Until Math.Abs((y2n - yn) / yn) <= eps
            y = y2n
            Console.WriteLine(" {0:f}  {1:f4}   {2:e1}   {3:e1}    {4}", x + 1, y2n, diff(x, y2n), h / (2 * n), 2 * n)

        Next i
        Console.ReadLine()
    End Sub

End Module
