using namespace std; int result [1000] = {0}; int fact (int num) { if (num >= 0) { result [0] = 1; for (int i = 1; i <= num; ++i) { result [i] = i * result [i - 1]; } return result [num]; } } int main () { int num; while (1) { cout<<"Please enter a number:"; GitHub Gist: instantly share code, notes, and snippets. This is demonstrated using the following program − Example. Example of both of these are given as follows. So here goes a java program to calculate factorial of 50 or 100 or other numbers: Factorial program in C using a for loop, using recursion and by creating a function. Your email address will not be published. Save my name, email, and website in this browser for the next time I comment. = 3*2*1 = 6. Solution¶ memo = {} def fact (n): if n in memo: return memo [n] elif n == 0: return 1 else: x = fact (n-1) * n memo … Multiple recursion with the Sierpinski gasket . public class Factorial { public static void main(String args[]) {int i, fact=1; int number=5; for(i=1;i<=number;i++) { fact=fact*i; } System.out.println("Factorial of "+number+" is: "+fact); } } Save the above code with any filename and .java extension. Dynamic Programming Top-down vs. Bottom-up zIn bottom-up programming, programmer has to do the thinking by selecting values to calculate and order of calculation zIn top-down programming, recursive structure of original code is preserved, but unnecessary recalculation is avoided. HackerEarth uses the information that you provide to contact you about relevant content, products, and services. = 1 if n = 0 or n = 1 Embed. Third method using Dynamic Programming; Example of Fibonacci Series: 0,1,1,2,3,5. What would you like to do? factorial (n) 1) Create an array ‘res []’ of MAX size where MAX is number of maximum digits in output. For example: 5! This C++ Program demonstrates the the computation of Factorial of a number using Dynamic Programming . C Program To Find Factorial of Large Numbers using Arrays. Recursive factorial. Code Explanation: Started with two variables “i” and “fact”, with value 1, then “number” with 5, which is our number to calculate the factorial. Yes this is dynamic programming : going from base cases up to final case.