VB学习第九周--计算π的近似值

前端之家收集整理的这篇文章主要介绍了VB学习第九周--计算π的近似值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click
        Dim n,t,s,m As Double
        m = Val(TextBox1.Text)
        s = 2.0#
        For n = 1 To m
            t = (2 * n) ^ 2 / ((2 * n - 1) * (2 * n + 1))
            s *= t
        Next
        Label2.Text = "π的近似值为" & s


    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class


原文链接:https://www.f2er.com/vb/258967.html

猜你在找的VB相关文章