0

factorial of large numbers

#include<stdio.h> int main() { int a[200],n,counter,temp,i; a[0]=1; counter=0; printf("Enter the number to Find Factorial: "); scanf("%d",&n); for(; n>=2; n--) { temp=0; for(i=0; i<=counter; i++) { temp=(a[i]*n)+temp; a[i]=temp%10; temp=temp/10; // } while(temp>0) { a[++counter]=temp%10; temp=temp/10; } } for(i=counter; i>=0; i--) printf("%d",a[i]); return 0; } how the first for loop and while

7th Jan 2020, 8:43 PM
Î DRØĮD
Î DRØĮD - avatar
9 Answers
+ 8
Factorial of any large number like 1000,10000 etc in java using BigInteger class https://code.sololearn.com/c7ZvCIQJZ2am/?ref=app
9th Jan 2020, 4:22 PM
Saroj Patel
Saroj Patel - avatar
0
Where are you getting wrong? It is not understandable by me what your doing? So can you specify errors... For a factorial, these kind of calculations are not necessary...
7th Jan 2020, 9:16 PM
Jayakrishna 🇮🇳
0
for loop and while loop forst one
7th Jan 2020, 9:16 PM
Î DRØĮD
Î DRØĮD - avatar
0
first
7th Jan 2020, 9:16 PM
Î DRØĮD
Î DRØĮD - avatar
0
If input is 3, then By for loop you get a[0]=3. And again changing to a[0]=6 by 2nd iteration.. Your code running like this... If it is 4, then a[0]=4, a[0]=4*3=12, by while loop a[1]=2 output:24 But for a factorial you need just N*( n-1) *( n-2) *... *1.
7th Jan 2020, 9:27 PM
Jayakrishna 🇮🇳
0
it is not mine i am trying to understand it
7th Jan 2020, 9:28 PM
Î DRØĮD
Î DRØĮD - avatar
0
OK. He is using some different algarithm there... Write like, In for loop, printf("\nin for loop %d,%d,%d",a[i],i,n); In while, printf("\nin while loop %d,%d",a[counter],counter); And make changes, in these according to your understandings.. And run it... You will find what changes are going on... Hoping it helps you...
7th Jan 2020, 9:56 PM
Jayakrishna 🇮🇳
0
https://www.google.com/amp/s/www.geeksforgeeks.org/factorial-large-number/amp/ Better explanation is given in this link. Check ones...
7th Jan 2020, 10:33 PM
Jayakrishna 🇮🇳