Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
final is 2 days!, factorial stuff
Old
miogi
Guest
 
Status:
Posts: n/a
Default final is 2 days!, factorial stuff - 12-10-2006, 03:19 PM

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!!

Miogi
   
Reply With Quote
Factorial problem.
Old
DrJim
Guest
 
Status:
Posts: n/a
Lightbulb Factorial problem. - 12-10-2006, 09:07 PM

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.

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! (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 simply 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
etc.

Hope this helps. Remember that while problems involving factorials can be difficult , calculating the value of a factorial itself is very simple.
Attached Files
File Type: zip factorials.zip (2.2 KB, 408 views)
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



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