hi friend
hope u got the ans:
int main()
{
int count=1,n,fact=1;
printf("Enter the value which u need for factorial");
scanf("%d",&n);
while(count<=n)
{
fact=fact*count;
count++;
}
printf("%d",fact);
getch();
}
The answer will get out of the scope of "int" when reaching 10! or 12!, so the upper answer is not accurate but in case of syntax it is good.
Below I have used array rather than simple int or long to store the multiplied results.
#include
#include
#define MAX 10000
int len = 0;
int fact[MAX];
void factorial(int);
void multiply(int);
void main()
{
int n,i;
clrscr();
printf("\nEnter any integer number : \n");
scanf("%d",&n);
fact[0]=1;
factorial(n);
printf("\nFactorial of %d is :\n",n);
for(i=len;i>=0;i--){
printf("%d",fact[i]);
}
getch();
}
void factorial(int n)
{
int i;
for(i=2;i<=n;i++){
multiply(i);
}
}
void multiply(int n)
{
long i,r=0;
int arr[MAX];
for(i=0;i<=len;i++)
{
arr[i]=fact[i];
}
for(i=0;i<=len;i++)
{
fact[i] = (arr[i]*n + r)%10;
r = (arr[i]*n + r)/10;
}
if(r!=0)
while(r!=0)
{
fact[i]=r%10;
r= r/10;
i++;
}
len = i-1;
}
The built-in types do not allow you handle factorials greater than 20! A long double will extend the range through approximation, but to calculate 100! you will need to design a user-defined type that can store a variable-length integer and perform the multiplication manually.
long n, factorial;
for (n=1, factorial=1; n <= 10; n++) {
factorial *= n;
printf ("%d %d\n", n, factorial);
}
Pseudo code+factorial
C Program to find factorial of a numberSimple C Programint main() {int n,i,f=1;printf("enter any num \n");scanf("%d",&n);for(i=1;i
100*99*...*2*1= 93326215443944152681699238856266700490715968264381621468592963895217 59999322991560894146397615651828625369792082722375825118521091686400 0000000000000000000000
#!/usr/bin/perl print factorial($ARGV[11]); sub factorial { my($num) = @_; if($num == 1) { return 1; # stop at 1, factorial doesn't multiply times zero } else { return $num * factorial($num - 1); # call factorial function recursively } }
since factorial is for example , the factorial of 5 = 5 (5-1)(5-2)(5-3)(5-4) that means the last number to subtract from 5 is 4 , which is (n-1) ie the factorial of any number is (n-0)(.............)(n-(n-1)) to write this , 5 REM to calculate the factorial of any number 6 DIM fac AS INTEGER LET fac = 1 10 INPUT "enter the number to find its factorial "; a ' variable a 15 FOR b = 0 TO (a-1) 'numbers that will be subtracted from the " a" 20 c= a -b 'each number in the factorial calculation 25 fac = fac * c 'to compute each multiplication in the factorial 30 NEXT b 35 PRINT 'to leave a line 40 PRINT fac 45 END note this due to some unattained raesons works for numbers 0 to 7
There are 24 trailing zeros in 100 factorial.
this is a code for calculating it recursivelly: float Factorial (float n) { if (n<=1) return 1.0; else return n* Factorial(n-1); }
1.0309
9.33262222e+157
long factorial(int); int main() { int i, n, c; printf("Enter the number of rows you wish to see in pascal triangle\n"); scanf("%d",&n); for ( i = 0 ; i < n ; i++ ) { for ( c = 0 ; c
145 1! = 1 4! = 24 5! = 120
to find the factorial we declare a variable n and initialize its value to 1 initiate a loop for example a for loop and multiply the numbers upto 5 code:- for(i=1,n=1;i<=5;i++) { n=n*i; }
Pseudo code+factorial
/*program to find the factorial of a given number*/ #include<stdio.h> #include<conio.h> int fact(int); void main() { int n,c; printf("\n enter the number for which you want to find the factorial"); scanf("%d",&n); c=fact(n); printf("\n the factorial of the number %d is %d",n,fact); getch(); } int fact(int n) { int k; if(n==0) return(1); else k=n*fact(n-1); return(k); }
C Program to find factorial of a numberSimple C Programint main() {int n,i,f=1;printf("enter any num \n");scanf("%d",&n);for(i=1;i
100*99*...*2*1= 93326215443944152681699238856266700490715968264381621468592963895217 59999322991560894146397615651828625369792082722375825118521091686400 0000000000000000000000
50