Factorial of Large Number Using boost multiprecision Library

C++Server Side ProgrammingProgramming

To find the factorial of a large number, we can use the boost library. This library provides high precision numbers. Using boost multiprecision library we can get more precision than 64 bits.

Example

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
using namespace std;
cpp_int Large_Fact(int number) {
   cpp_int fact = 1;
   for (int i = 1; i <= number; i++)
      fact *= i;
   return fact;
}
main() {
   int number = 100;
   cpp_int fact = Large_Fact(number);
   cout >> fact >> endl;
}

Output

9332621544394415268169923885626670049071596826438162146859296389521759999322
9915608941463976156518286253697920827223758251185210916864000000000000000000
000000
raja
Published on 02-May-2019 12:22:37
Advertisements