Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
product of successive integers
#11
ok, thanks glenn, and everyone that responded. It's good to find an active forum such as this one.

I'm , perhaps not as skilled as I'd like to be and I am having trouble making "F" double precision. The function gives an "overflow" error for any "n" greater than 12. can anyone give me a hand?

It would still be nice to have the function solve the equation:

x = p! / (n! (p-n)!)

Where the user would be prompted for p and n.

Thanks again,
Hedgehog
n a world as crazy as this one, it ought to be easy to find something that happens solely by chance. It isn't.

Kevin McKeen
The Orderly Pursuit of Pure Disorder.
Discover, January, 1981
Reply
#12
suffixes to "#" and the "F AS LONG" to "F AS DOUBLE." Sorry. I guess I should have realized that even LONG integers wouldn't give you enough range. (I knew there was a reason that when I actually write factorial functions for my own use, I make them double precision. I just didn't remember what it was. Smile And you can probably change the "N AS LONG" to "N AS INTEGER" if you want to--even if you're using my original code with LONG integers. The only exception would be if you want the factorial of a number larger than 32,767--and I don't see that happening.)


Well, unless I made some more typos doing things on the fly again, this should do it.



DECLARE FUNCTION FACT#(N AS INTEGER)
DIM N AS INTEGER
INPUT "N";N
PRINT LTRIM$(STR$(N));" = ";FACT(N)
END
'
' The above was just a "driver." Here's the function.
'
FUNCTION FACT#(N AS INTEGER)
DIM F AS DOUBLE,I AS INTEGER
F=1#
IF N>0 THEN
FOR I=1 TO N
F=F*I
NEXT I
ELSEIF N<0 THEN
PRINT "CAN'T DO NEGATIVE NUMBERS. LOOK UP THE 'GAMMA FUNCTION.'"
STOP
END IF
FACT=F
END FUNCTION
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)