#include
void main()
{
int n;
clrscr();
printf("enter number: ");
scanf("%d",&n);
if(n<0)
printf("invalid number");
else
printf("%d!=%d",n,fact(n));
getch();
}
int fact(int x)
{
if(x==0)
return 1;
else
return(x*fact(x-1));
}
Output:
enter number: 5
5!=120
No comments:
Post a Comment