
Option Strict On
Imports System.IO
Module Module1
    Const k2 As Double = 0.0065
    Const k1 As Double = 0.05
    Dim A0 As Double = 1
    Function dp(ByVal p As Double, ByVal t As Double) As Double
        Return k1 * A0 * Math.Exp(-k1 * t) - k2 * p
    End Function
    Sub Main()
        Const OutputFile As String = "output.csv"
        Const p0 As Double = 0
        Dim Output As StreamWriter
        Dim t0, tk, st, tprev As Integer
        Dim p, pprev As Double
        Output = New StreamWriter(OutputFile)
        t0 = 0 : tk = 500 : st = 10
        tprev = t0 : p = p0
        Console.WriteLine("Расчет методом Эйлера кинетики хим.реакции")
        Console.WriteLine()
        Console.WriteLine("Начальное значение t; {0}", t0)
        Console.WriteLine("Начальное значение P; {0}", p0)
        Console.WriteLine("Конечное значение t; {0}", tk)
        Console.WriteLine("Шаг интегрирования; {0}", st)
        Console.WriteLine()
        Console.WriteLine("  t; [P]")
        For t As Integer = t0 To tk Step st
            tprev = t : pprev = p
            Console.WriteLine("{0,3}; {1}", t, p)
            Output.WriteLine("{0,3}      {1}", t, p)
            p = pprev + st * dp(pprev, tprev)
        Next t
        Output.Close()
        Console.ReadLine()
    End Sub

End Module
