Find the factorial of 100 in C++?

Find the factorial of 100 in C++?

the only option is to use string and basic mathematical operations as no data type can store that huge number .

1 Like

would u plz code it…

use an array of integer and implement in such a way that this array can store huge data

I am giving the code for implementing this type of array

The Formula of fact(n) is n*(n-1)(n-2)…321

means you have to multiply and this will give you a huge number that you cannot store in any data type.

              int a[170];
              temp = 0;
              for(i=1;i<=n;i++)  // to multiply n number 
                                               x = a[j]*i+temp;
                                               temp = x/10;
                                 temp = temp/10;

Now print the array element from m-1 to 0 index;

You can also follow my code for [this][1] problem

My code is :


If you still have any doubt in this method you may ask me.

Happy Coding!!!


@alokamaster : i would rather advise you to try this as an assignment. you will definitely learn the art of dealing with operations of large numbers…

secondly, you will get introduced to the concept of polynomial multiplications and how to use Fourier transform to do the same!!

1 Like

Have you tried If you’re still having difficulty with understanding the approaches outlined in the previous answers, go to the tutorial of the aforementioned problem, where a detailed and very well written explanation of roughly the same approach can be found.

learn python

C++ doesn’t data types to store such large values as 100! will have approx 150 digits, where as long long int support only 4*10^18. So, you need to handle big integers with the help of arrays…U can take help from this link on how to handle large numbers…! “”…

1 Like

You can use c++ boost library for multiplication of very large numbers… to find 100! use boost library for large multiplication…

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using namespace std;

mp::cpp_int fact(mp::cpp_int a)
		return 1;
		return 0;
	return a * fact(a-1);

int main()
	int t;
		mp::cpp_int a;
	return 0;

actually this is solution to FCTRL2 problem…

1 Like

Using Boost Library