Here you will get the program to discover factorial of an enormous number in C and C++.
Factorial of huge numbers contain such a large number of digits. For instance factorial of 100 has just about 158 digits.
So there is no information type accessible to store such a long worth. Yet, we can discover factorial for enormous numbers utilizing basic augmentation
technique that we utilized in our educational time. Underneath I have shared the program for it.
Program for Factorial of Large Number in C
#include<stdio.h>
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;
printf("Enter any large number:");
scanf("%d",&n);
for(i=2;i<=n;++i) {
size=multiply(i,a,size);
}
for(i=size-1;i>=0;--i)
{
printf("%d",a[i]);
}
return 0;
}
Program for Factorial of Large Number in C++
#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;
}
Output
On the off chance that you have any uncertainty in regards to the
above program, at that point, you can ask it by remarking beneath.