Javatpoint Logo
Javatpoint Logo

Extra Long Factorials in C

Problem Statement: The factorial of the integer n, written n!, is defined as:

n! = n x (n-1) x (n-2) x (n-3) x ………. x 3 x 2 x 1

Calculate and print the factorial of a given integer.

For example, if n = 30 , we calculate 30 x 29 x 28 x ………..x 3 x 2 x 1 and get.

2 6 5 2 5 2 8 5 9 8 1 2 1 9 1 0 5 8 6 3 6 3 0 8 4 8 0 0 0 0 0 0 0 in total 33 digits.

Note: Factorials of n > 20 can't be stored even in a 64 - bit long variable. Big integers must be used for such calculations. Languages like Java, Python, Ruby etc. can handle big integers, but we need to write additional code in C/C++ to handle huge values.

Description of program : The below program can calculate factorial of any number, i.e. factorial of numbers above 20 which is not feasible for an 64 bit computer.

We have started with variable

Output of above Code

Extra Long Factorials in C






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA