Factorial Program in C

Posted 18 November 2012 - 04:20 PM

Hello DreamInCode!

I have been working though JAVA and C programming the past few months and i found this example that looks like a challenge. I have been posting these while i am doing them because allot of you have great input on my programming. Its one thing to do it but another to have others comment on it for improvements and answer pressing issues. People on here respond allot faster than people that i have on my email list.

Thank you for looking at this post and thank you very much for all help Past, Present, and Future!

__________________
Have the user enter a list of numbers and place them into an array (since we have not done dynamic arrays yet, create a static array that can hold at least 25 items and limit the user to that many items).

You will need to write two methods, one to find the factorial of a number and the other to sum the factorials of the array. These methods will invoke the following signatures:

int factorial(int number);

int sumFactorial(int list[], int numberElements);

For each item in the array, you will need to display the number and itís factorial. At the end, display the sum of the factorials.

Example run:

Enter Number Elements: 5

Element 1: 2

Element 2: 3

Element 3: 1

Element 4: 6

Element 5: 7

f(2) = 2

f(3) = 6

f(1) = 1

f(6) = 720

f(7) = 5040

sum of factorials = 5769

Validation: Ensure the user enters a value for the number of elements less than or equal to you array size and accept only positive numbers for the values to be placed in the array. If an invalid entry is made, prompt the user for another entry (donít exit the program).

Re: Factorial Program in C

Coz if you have, then doing a factorial program with recursion is probably the simplest of things ever />

If you want to know what recursion is, I would suggest you go through This link(only the recursion part) to see how it works. />

regards,
Raghav

I wouldn't say learned, but i have dabbled in it and have used it before. Thank you very much for the input!!!! i have added the implementation of recursion to my code. Looking back that is probably what they wanted me to do in the first place.