[VB.NET]VB编程问题急救

来源:互联网 发布:部落冲突黑水罐数据 编辑:程序博客网 时间:2024/05/22 06:33
VB.NET源码-156个实用实例哦……<script type="text/javascript"><!--google_ad_client = "pub-8333940862668978";/* 728x90, 创建于 08-11-30 */google_ad_slot = "4485230109";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
VB编程问题急救

各位帮忙编个程序,本人感激不尽啊
在窗体上输出1到500的所有同构数的。

所谓同构数:指本身的平方的末几位于自身相同的数。

例如:5的平方25,最后一位为5

又例如:25的平方625,最后两位为25

要求:Form的Click事件发生时,输出程序运行结果
__________________________________________________________________________
Private Sub FormInVB_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
Dim nLoop As Integer = 1

While (nLoop < 501)
If (CheckTail(nLoop, nLoop * nLoop)) Then
Debug.WriteLine(nLoop.ToString() + : + (nLoop * nLoop).ToString())
End If
nLoop = nLoop + 1
End While
End Sub

Private Function CheckTail(ByVal num1 As Integer, ByVal num2 As Integer) As Boolean
If (num1 = 0) Then
Return True
End If

If ((num1 Mod 10) = (num2 Mod 10)) Then
Return ((True) And (CheckTail(Decimal.Floor(num1 / 10), Decimal.Floor(num2 / 10))))
Else
Return False
End If
End Function
__________________________________________________________________________
输出
1 : 1
5 : 25
6 : 36
25 : 625
76 : 5776
376 : 141376
__________________________________________________________________________
唉,看来VB比C慢很多,把循环中的if判断去掉,计算 While (nLoop < 50000001) (C里面是 while ( nLoop < 50000001L ) ),VB需要 1.796 秒,而 C 只需要 0.125,相差十几倍啊
__________________________________________________________________________
原创粉丝点击