• 0

vb.net factorial


Question

7 answers to this question

Recommended Posts

  • 0
   Function calculateFactorial(ByVal number As Integer) As Double
        Dim factorial As Double = 1.0
        For i As Double = 1.0 To number
            factorial = factorial * i
        Next
        Return factorial
    End Function


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MessageBox.Show(Me.calculateFactorial(4))
    End Sub

  • 0
  gameguy said:
You don't need to use doubles :huh: Integers work fine; if you're using large numbers, use longs (System.Int64, I forget what VB calls them) (Y)

But otherwise, Winston's code is right :yes:

584779593[/snapback]

I wasn't too sure, i had to use doubles, i tested it out inside the normal windows calc and put in say 90!, and it gave a double back, so i just used double and it works fine, so meh :)

  • 0
  Winston said:
I wasn't too sure, i had to use doubles, i tested it out inside the normal windows calc and put in say 90!, and it gave a double back, so i just used double and it works fine, so meh :)

584781686[/snapback]

Well the factorial of 90 is an absolutely enormous number, so what do you expect? :p

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.