Calculate the factorial of a number

Reply

Join Date: Mar 2004
Posts: 1
Reputation: zeakman is an unknown quantity at this point 
Solved Threads: 0
zeakman zeakman is offline Offline
Newbie Poster

Calculate the factorial of a number

 
0
  #1
Mar 25th, 2004
need help with basic program.trying to write a program in qbasic to take in a integer calculate and print out the factorial.been on this for a long time
Reply With Quote Quick reply to this message  
Join Date: May 2003
Posts: 307
Reputation: big_k105 is an unknown quantity at this point 
Solved Threads: 2
Team Colleague
big_k105's Avatar
big_k105 big_k105 is offline Offline
PFO Founder

Re: Calculate the factorial of a number

 
1
  #2
Apr 3rd, 2004
could you possibly post the code you have so we can tell exactly what you need help with. that would make it easier to help up thanks
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 7
Reputation: SleepDepD is an unknown quantity at this point 
Solved Threads: 0
SleepDepD's Avatar
SleepDepD SleepDepD is offline Offline
Newbie Poster

Re: Calculate the factorial of a number

 
0
  #3
Apr 28th, 2004
I haven't coded in QBasic in years, but in VB it would be like the following:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim intNumber As Integer
  2. Dim lngFactorial As Long
  3. Dim lngCounter As Long
  4.  
  5. intNumber = 5
  6.  
  7. For lngCounter = 1 To intNumber
  8. lngFactorial = lngFactorial * lngCounter
  9. Next lngCounter

"lngFactorial" would then be your number. Is this what you're looking for?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 7
Reputation: scisoft is an unknown quantity at this point 
Solved Threads: 0
scisoft scisoft is offline Offline
Newbie Poster

Re: Calculate the factorial of a number

 
0
  #4
Apr 30th, 2004
If you do not use logarithmus, you will be getting overflow error for factorial of integers larger then approx. 280.
This is VB6 code:
Dim l As Long
Dim res As Double
For l = 1 To total
res = res + Log(CDbl(l))
Next


The final result "res" is used for furhter mathematical operation, rather then directly printing its value val= Exp(res), since if val is too high, you would just get the overflow error.
SEO
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC