Need Help on factorial

Apr 28, 2016 at 3:07am
Write a program to prompt the user to key in x and n value to calculate the result for the following formula:
Result = 1 + 2!/(x-2) - 3!/(x-3)+ 4!/(x-4)-.....n!/(x-n)

Note: x value must be greater than n value.

Sample Run 1
Please key in x value : 8
Please key in n value : 5
Result: 1 + 2!/6 + 3!/5 + 4!/4 + 5!/3 =-33.8667

Please help me
Last edited on Apr 28, 2016 at 3:07am
Apr 28, 2016 at 4:22pm
Result = 1 + 2!/(x-2) - 3!/(x-3)+ 4!/(x-4)-.....n!/(x-n)
Result:_ 1 + 2!/6___+ 3!/5__+ 4!/4___+ 5!/3 =-33.8667


Not sure which is correct, your question statement or sample run. Fix the question and show your best effort, stating where you're having trouble.
Apr 29, 2016 at 2:37am
it appears he just trying to calculate a taylor polynomial. I would suggest start by breaking the requirements down into manageable pieces.

1) Write a function called factorial that will calculate the factorial of a number. You need to be strict on the requirements because this can quickly overflow for large values of N if you are using primitive types. For large values of N, you will need to write you own data-structure to hold large numbers. If you want to make the function efficient, look into a technique called memoization.

Once you have that taken care of, the rest should be fairly easy. Once you have some code post back here, and I will help the best I can. I don't want to give to much away if this is homework though.
Topic archived. No new replies allowed.