Alice Community

Alice Community (
-   How do I...? (
-   -   final is 2 days!, factorial stuff (

miogi 12-10-2006 02:19 PM

final is 2 days!, factorial stuff
I have my final test on Tuesday and there will be an asignment todo at the end of the test regarding factorial like f(n>1) stuff and I dont understand it at all!, could you please if you have time explain to me in words that I can understand? My teacher goes over like 99% of our classes heads with this stuff and I want to do good with this last test to bring up my average if I can. the kind of question he is going to ask is solve the following problem using factorial with a while loop. and another is define the factorial problem using recursion. Now I have tried to google this and read my notes, I just frankly dont understand it. I am hoping that you can help me.. Thanks in advance..

anyhelp in , or to put me in the right direction would be great!!


DrJim 12-10-2006 08:07 PM

Factorial problem.
1 Attachment(s)
This one is a bit hard to give hints on without spelling out the solution - also a solution would be a bit hard to memorize even if I did - ironically because it would be so brief that it would also be very easy to goof up. :rolleyes:

What I do if for some reason I need to calculate a factorial - and don't have a calculator with that function programmed in - is to just run through the calculation of the first few factorials by hand and then write a quick program duplicating the hand approach. The attached spreadsheet shows one example - note that factorials get large very quickly! :eek: (It was done in Works but you should be able to open it in Excel and most other spreadsheet programs.)

My first suggestion is that you do a similar calculation by hand and then try to figure out how to do it with a loop and recursively. Note that with the recursive approach, any local variables will be reset each time the method calls itself - so if you want to use something in multiple executions of a method, it has to be a world level variable.

Second, make sure to remember that the factorial of a number is [B]simply[/B] the product of all integers up to and including that number. Hence
1! = 1
2! = 1 x 2 = 1! x 2 = 2
3! = (1 x 2) x 3 = 2! x 3 = 6
4! = (1 x 2 x 3) x 4 = 3! x 4 = 24

Hope this helps. Remember that while problems [I]involving[/I] factorials can be difficult :p , calculating the value of a factorial itself is [B]very[/B] simple.

All times are GMT -5. The time now is 03:04 PM.

Copyright ©2019, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.