VB编程问题急救

youyouaimo 2007-04-02 08:20:47

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

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

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

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

要求:Form的Click事件发生时,输出程序运行结果

...全文
193 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
neil_cn 2007-04-02
  • 打赏
  • 举报
回复
唉,看来VB比C慢很多,把循环中的if判断去掉,计算 While (nLoop < 50000001) (C里面是 while ( nLoop < 50000001L ) ),VB需要 1.796 秒,而 C 只需要 0.125,相差十几倍啊
neil_cn 2007-04-02
  • 打赏
  • 举报
回复
输出
1 : 1
5 : 25
6 : 36
25 : 625
76 : 5776
376 : 141376
neil_cn 2007-04-02
  • 打赏
  • 举报
回复
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

16,718

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧