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
9 Answers
+ 8
Factorial of any large number like 1000,10000 etc in java using BigInteger class
https://code.sololearn.com/c7ZvCIQJZ2am/?ref=app
+ 5
https://code.sololearn.com/c3eg8MvlATAf/?ref=app
https://code.sololearn.com/cOInw4yJq7wi/?ref=app
https://code.sololearn.com/cE7lXk0wwKMN/?ref=app
https://code.sololearn.com/c4phTP2wUQ3u/?ref=app
https://code.sololearn.com/cOfMIY803RdZ/?ref=app
https://code.sololearn.com/c4Q0rFUFxZIP/?ref=app
https://code.sololearn.com/cj7pAcAEmqTm/?ref=app
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...
0
for loop and while loop forst one
0
first
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.
0
it is not mine i am trying to understand it
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...
0
https://www.google.com/amp/s/www.geeksforgeeks.org/factorial-large-number/amp/
Better explanation is given in this link. Check ones...