+ 1

How to find factorial of large number in c++?

Factorial of number even unsigned long long int can hold

20th May 2017, 9:47 AM
Bishal Sarang
Bishal Sarang - avatar
3 odpowiedzi
+ 2
#include<iostream> using namespace std; int multiply(int x,int a[],int size) { int carry=0,i,p; for(i=0;i<size;++i) { p=a[i]*x+carry; a[i]=p%10; carry=p/10; } while(carry!=0) { a[size]=carry%10; carry=carry/10; size++; } return size; } int main() { int n,a[1000],i,size=1; a[0]=1; cout<<"Enter any large number:"; cin>>n; for(i=2;i<=n;++i) { size=multiply(i,a,size); } for(i=size-1;i>=0;--i) { cout<<a[i]; } return 0; }
14th Oct 2017, 2:44 AM
Core i9
Core i9 - avatar
0
I built a really big number arithmetic processor where a number was treated as a number but stored as a string. It could do math with 2000 + digits, and maybe much more.
20th May 2017, 9:54 AM
Testing002
0
!!!!!
11th Jun 2017, 5:44 PM
Thapakaji
Thapakaji - avatar