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

VB.NET源码-156个实用实例哦…… <script type="text/javascript"> </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,相差十几倍啊
__________________________________________________________________________
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值