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:

Input : 100
Output :  933262154439441526816992388562667004-
         907159682643816214685929638952175999-
         932299156089414639761565182862536979-
         208272237582511852109168640000000000-
         00000000000000



Input :50
Output : 3041409320171337804361260816606476884-
         4377641568960512000000000000



filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:-

933262154439441526816992388562667004-
         907159682643816214685929638952175999-
         932299156089414639761565182862536979-
         208272237582511852109168640000000000-
         00000000000000


My Personal Notes arrow_drop_up

Sometimes you never realize the value of a moment until it becomes a memory

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


8


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.