We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
C++intmultiply(intx,intres[],intres_size){intcarry=0;// Initialize carry// One by one multiply n with individual digits of res[]for(inti=0;i<res_size;i++){intprod=res[i]*x+carry;// Store last digit of 'prod' in res[]res[i]=prod%10;// Put rest in carrycarry=prod/10;}// Put carry in res and increase result sizewhile(carry){res[res_size]=carry%10;carry=carry/10;res_size++;}returnres_size;}voidextraLongFactorials(intn){intres[MAX];// Initialize resultres[0]=1;intres_size=1;// Apply simple factorial formula n! = 1 * 2 * 3// * 4...*nfor(intx=2;x<=n;x++)res_size=multiply(x,res,res_size);for(inti=res_size-1;i>=0;i--)cout<<res[i];}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Extra Long Factorials
You are viewing a single comment's thread. Return to all comments →