您的位置:程序门 -> .net技术 -> vb.net



vb编程问题急救


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


vb编程问题急救
发表于:2007-04-02 20:20:47 楼主

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

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

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

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

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

发表于:2007-04-02 21:48:141楼 得分:0
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
发表于:2007-04-02 21:49:272楼 得分:0
输出
1   :   1
5   :   25
6   :   36
25   :   625
76   :   5776
376   :   141376
发表于:2007-04-02 22:08:213楼 得分:0
唉,看来vb比c慢很多,把循环中的if判断去掉,计算   while   (nloop   <   50000001)   (c里面是   while   (   nloop   <   50000001l   )   ),vb需要   1.796   秒,而   c   只需要   0.125,相差十几倍啊


快速检索

最新资讯
热门点击