Example: 5!=5*4*3*2*1=120
---------------
#include<stdio.h>
#include<conio.h>
int factorial(int n)
{
if(n<0)
return 0;
else if(n<=1)
return 1;
else
return (n*factorial(n-1));
}
void main()
{
int fact,n;
printf("\nEnter number:");
scanf("%d",&n);
fact=factorial(n);
printf("\nFactorial of %d is :%d ",n,fact);
getch();
}
---------------
#include<stdio.h>
#include<conio.h>
int factorial(int n)
{
if(n<0)
return 0;
else if(n<=1)
return 1;
else
return (n*factorial(n-1));
}
void main()
{
int fact,n;
printf("\nEnter number:");
scanf("%d",&n);
fact=factorial(n);
printf("\nFactorial of %d is :%d ",n,fact);
getch();
}
thanks
ReplyDelete