Extra Long Factorial
Question :-
https://www.hackerrank.com/challenges/extra-long-factorials/problem
Solution in C++ language :-
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int arr[100000]={0};
int leng=1,x=0,num=0,i;
arr[0]=1;
for(i=2;i<=n;i++){
x=0;
num=0;
while(x<leng){
arr[x]=arr[x]*i;
arr[x]=arr[x]+num;
num=arr[x]/10;
arr[x]=arr[x]%10;
x++;
}
while(num!=0){
arr[leng]=num%10;
num=num/10;
leng++;
}
}
for(i=leng-1;i>=0;i--){
cout<<arr[i];
}
return 0;
}
Comments
Post a Comment