943,837 Members | Top Members by Rank

Ad:
Mar 25th, 2004
0

Calculate the factorial of a number

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zeakman is offline Offline
1 posts
since Mar 2004
Apr 3rd, 2004
1

Re: Calculate the factorial of a number

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
Team Colleague
Reputation Points: 36
Solved Threads: 2
PFO Founder
big_k105 is offline Offline
308 posts
since May 2003
Apr 28th, 2004
0

Re: Calculate the factorial of a number

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
SleepDepD is offline Offline
7 posts
since Apr 2004
Apr 30th, 2004
0

Re: Calculate the factorial of a number

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
scisoft is offline Offline
7 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Preprocessor directives
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: HELP with VB project





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC