954,184 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Calculate the factorial of a number

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

zeakman
Newbie Poster
1 post since Mar 2004
Reputation Points: 10
Solved Threads: 0
 

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 :)

big_k105
PFO Founder
Team Colleague
357 posts since May 2003
Reputation Points: 36
Solved Threads: 2
 

I haven't coded in QBasic in years, but in VB it would be like the following:

Dim intNumber As Integer
Dim lngFactorial As Long
Dim lngCounter As Long
 
intNumber = 5
 
For lngCounter = 1 To intNumber
  lngFactorial = lngFactorial * lngCounter
Next lngCounter


"lngFactorial" would then be your number. Is this what you're looking for?

SleepDepD
Newbie Poster
7 posts since Apr 2004
Reputation Points: 10
Solved Threads: 0
 

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.

scisoft
Newbie Poster
7 posts since Apr 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You