Extra long factorials code in C#

Problem source: https://www.hackerrank.com/challenges/extra-long-factorials

You are given an integer N. Print the factorial of this number.


Note: Factorials of N>20 can’t be stored even in a 64bit long 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 such large values.

We recommend solving this challenge using BigIntegers.

Input Format
Input consists of a single integer N.


Output Format
Output the factorial of N.

Sample Input


Sample Output


class Extra_Long_Factorials_Hackerrank
static void Main(string[] args)
int N = Convert.ToInt16(Console.ReadLine());

private static BigInteger Factorials(int N)
if (N == 1)
return 1;
return N * Factorials(N – 1);


One thought on “Extra long factorials code in C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s