Factorial of Large Number Using boost multiprecision Library
We have given a large number now we can easily find out the factorial of this large number using boost multiprevision Library.
Boost library has included a new multiprecision library in the current 1.53.0 release for C++ programmers who need more precision than 64 bits.
Examples:
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Input : 100
Output : 933262154439441526816992388562667004-
907159682643816214685929638952175999-
932299156089414639761565182862536979-
208272237582511852109168640000000000-
00000000000000
Input :50
Output : 3041409320171337804361260816606476884-
4377641568960512000000000000
// CPP program to find factorial of large // number using boost library.#include <bits/stdc++.h>#include <boost/multiprecision/cpp_int.hpp>using boost::multiprecision::cpp_int;using namespace std; cpp_int Factorial(int number){ cpp_int num = 1; for (int i = 1; i <= number; i++) num = num * i; return num;} int main(){ int number = 100; cpp_int fact = Factorial(number); cout << fact << endl; return 0;} |
Output:-
933262154439441526816992388562667004-
907159682643816214685929638952175999-
932299156089414639761565182862536979-
208272237582511852109168640000000000-
00000000000000

