Wrox Programmer Forums
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 1st, 2008, 03:50 AM
Registered User
 
Join Date: May 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default help with finding zeros of !

hi all

im trying to write a code to find number of zeros of 100! but cant get it to work properly?
help would be good
heres the code ive done so far

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer = 0
        Dim num As Integer = 0
        Dim start As Integer = 0
        Dim theend As Integer = 100


        While (start <= 100)

            num = start
            While (start Mod 5 = 0)
                start = start / 5
                i += 1

            End While
            start = num

            While (start Mod 2 = 0)

                start = start / 2
                start += 1

            End While

        End While

        Label1.Text = i





    End Sub
End Class


 
Old May 1st, 2008, 04:08 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

First of all, all numeric variable types initialize to 0. Your initializations are unnecessary.
You never use theend
You sould think about posing questions in proper capitalization and punctuation (notably, apostrophes...)
If you mean the number of zeroes [u]in</u>, that's actually much easier with strings.
Convert 100 to "100", and then examine each character for "0".

Start starts as 0. 0 Mod 5 = 0, so the while happens.
0 / 5 = 0, so start stays as 0
i gets incremented.
The while compares 0 Mod 5 again. and again. and again. Until i overflows.

Could you explain in a little more detail (and a little better writing) what it is that you want to do, and include what your results so far have been?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing leading zeros from a string value vikkiefd XSLT 2 June 12th, 2008 03:30 AM
Remove Leading and Trailing Zeros lene_wee SQL Server 2000 3 April 1st, 2008 08:23 AM
Padding Zeros jmss66 Classic ASP Basics 5 January 28th, 2008 07:38 PM
Suppress zeros from displaying smatyk SQL Server 2000 8 October 27th, 2006 08:12 AM
Zeros at left... comicghozt Access 7 October 3rd, 2006 02:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.