| dovip (16) | |
|
Write a program that defines and tests a factorial function. The factorial of a number is the product of all whole numbers from 1 to N. For example, the factorial of 5 is 1 * 2 * 3 * 4 * 5 = 120. (Hint: Use a for loop as described in Charter 3) Please help me, my slowly reader is sometimes problem because I still don't get it all. Thanks. | |
|
|
|
| pogrady (410) | |
| What do you have? | |
|
|
|
| Darkmaster (341) | |
|
for(int i =1;i<=number;++i) { result*=i; } | |
|
|
|
| jumper007 (302) | |||
|
If you had a little bit of knowledge about functions, you could use a recursive function too. Anyways, that wouldn't be better. As @Darkmaster said, the required version for calculating the factorial in your exercise is:
Best of wishes, ~ Raul ~ | |||
|
Last edited on
|
|||
| nathan10 (120) | |
| Don't forget the condition for N = 0. And something to prevent negative numbers. | |
|
|
|
| dovip (16) | |
| Oh I understand now. Thank you guys. | |
|
|
|