Program to find factorial of a number using recursive function.
#include<stdio.h>
int factorial(int n);
int main()
{
int n,f;
printf("Enter an positive integer: ");
scanf("%d",&n);
f=factorial(n);
printf("Factorial of %d = %d", n,f );
return 0;
}
int factorial(int n)
{
if(n!=1)
return (n*factorial(n-1));
}
Output:
Comments
Post a Comment