#include<conio.h>
#include<stdio.h>
int fact(int p);
void main()
{
int n, ans;
clrscr();
printf(“Enter the number:”);
scanf(“%d”,&n);
ans = fact(n);
printf(“Factorial of a given number %d is %d”,n,ans);
getch();
}
int fact(int p)
{
if(p==1)
{
return 1;
}
else
{
return p*fact(p-1);
}
}
OUTPUT:
Enter the number: 3
Factorial of a given number 3 is 6
No comments:
Post a Comment