среда, 24 декабря 2014 г.

6 лабораторная код 1

Option Explicit On
Option Strict On
Imports System.Math

Partial Class Form1
    Public Sub Resh(ByVal x As Double, ByVal eps As Double, ByVal n As Integer)

        Dim z As String
        Dim z1 As String
        Dim z3 As String

        Dim last_n As String
        Dim last_a As String
        Dim last_sum As String


        'сумма
        Dim sum As Double

        'элемент ряда
        Dim a As Double


        'Присвоение начальных значений

        z = " "
        z1 = "|"
        z3 = "  "

        sum = 0


        a = (x - 1) / x

        ListBox1.Items.Add(z)

        'Начало цикла

        Do Until Abs(a) < eps

            z = " "
            z1 = "|"


            sum = sum + a

            z = z + Space(15) + z1 + Space(6) + Format(n, "0000") + Space(6) + z1 + Space(6) + Format(a, "000000.000000") + Space(6) + z1 + Space(6) + Format(sum, "000.0000000000") + Space(6) + z1

            ListBox1.Items.Add(z)

            last_a = CStr(Format(a, "0.000000"))
            last_n = CStr(n)

            n = n + 1
            a = (a * n * (x - 1)) / (x * (n + 1))

        Loop



        last_sum = CStr(Format(sum, "000.0000000000"))

        vivod(last_n, TextBox4)
        vivod(last_a, TextBox5)
        vivod(last_sum, TextBox6)


    End Sub

    Sub vivod(ByVal W As String, ByRef T As TextBox)

        T.Text = CStr(W)

    End Sub


    Function vvod_int(ByVal K As TextBox) As Integer

        Return CInt(Val(K.Text))

    End Function

    Function vvod(ByVal T As TextBox) As Double

        Return CDbl(Val(T.Text))

    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim x As Double
        Dim eps As Double
        Dim n As Integer

        x = vvod(TextBox1)
        eps = vvod(TextBox2)
        n = vvod_int(TextBox3)

        Resh(x, eps, n)

    End Sub


End Class

Комментариев нет:

Отправить комментарий