Factorial of N

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2008
Posts: 65
Reputation: lich has a little shameless behaviour in the past 
Solved Threads: 4
lich lich is offline Offline
Junior Poster in Training

Factorial of N

 
0
  #1
Jun 1st, 2008
I really dont know this Program is rite or wrong. but it wont give a answer. if anyone can help me in this

Public Class Form2
Dim num As Integer

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fact As Integer

num = Val(InputBox("Enter the Factorial Number"))


Do
fact = fact * num
num = num - 1

Loop Until num <= 0


MessageBox.Show(fact)



End Sub
End Class
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Factorial of N

 
1
  #2
Jun 1st, 2008
use this following function :
  1. Public Function Factorial(ByVal Number As Integer) As String
  2. Try
  3. If Number = 0 Then
  4. Return 1
  5. Else
  6. Return Number * Factorial(Number - 1)
  7. End If
  8. Catch ex As Exception
  9. Return ex.Message
  10. End Try
  11. End Function
I called this function in button click event:
  1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  2. Dim num As Integer
  3. num = Val(InputBox("Enter the Factorial Number"))
  4. MsgBox(Factorial(num))
  5. End Sub
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC