|
Post by rowbot on Jul 17, 2006 20:33:08 GMT
I need a generic factorial routine for QB 1.1, new to QB and new to this forum.
Thanks ahehead of time,
rowbot.
|
|
|
Post by Ildûrest on Jul 18, 2006 13:21:32 GMT
Let me quote forum policy (which is nice and easy to find up the top of the forum): "We don't make programs on demand for you (especially not homework)."
Remember that we provide help of our own good will and as such would rather not write up a program that's only going to be used to make your teacher think you did your homework. This is fairly trivial however so I'm not going to stress too much, but in future, you should provide what you have tried so far and explain where your problem is as specifically as possible.
Now to tackle the problem.
The definition of factorial N is the multiple of all integers from 1 to N (for N >= 1)
So how do we do this programatically? We "build up" to our goal. We start with 1, multiply by 2, multiply by 3, and so on. So we need a variable to store our current quantity. We also need a variable to store what number we're up to multiplying by.
I provide the following code trusting you will actually make an effort to understand it. I make the assumption that you understand how a FOR-NEXT works (and if you don't I welcome you to ask). N=5 Factorial = 1
FOR I = 2 TO N Factorial = Factorial * I NEXT
PRINT Factorial
Welcome to the forum, rowbot.
|
|
|
Post by Hammas on Nov 1, 2017 18:29:24 GMT
Hey can you help me please I understand qb64 but I am stuck at factorial. I know how it works but I am maybe making a mistake. Can you do an example of a factorial coding. Thanks in advance.
|
|