2017年12月12日 星期二

[ VB2010 ] - 求平方根

[ VB2010 ] - 求出X的平方根

以疊代的方式找出小數1位的解:

求出10的平方根  3.15






Public Class Form1

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

        Dim X As Double = 1.0
        Dim Y, Y1, Y2 As Double
        Dim P, I As Double
        Y1 = Val(TextBox1.Text)
        TextBox3.Text = ""

        Y = Math.Round(Math.Sqrt(Y1) + 0.8)

        TextBox4.Text = Y.ToString("#.###")

        For I = X To Y Step 0.05
            P = I * I
            Y2 = (P - Y1)
            TextBox5.Text &= Y2.ToString("#.###") & vbCrLf

            If Y2 < 0 Then
                TextBox3.Text &= I.ToString("#.####") & "*" & I.ToString("#.####") & "=" & P.ToString("#.####") & vbCrLf
            End If
        Next

    End Sub


    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub
End Class

沒有留言:

張貼留言

2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2

 2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2 AngularJS 實例 <!DOCTYPE html> <html> <head> &...