C Program to Find Factorial of Number using Recursion

Write a Program to Find Factorial of Number using Recursion

// C Program to Find Factorial of Number using Recursion

#include <stdio.h>

int fact(int n)
{
	int product = 1;
	if(n == 0 || n == 1 )
		return n;
	return n * fact(n-1);
}

int main()
{
	int n;

	printf("Enter Number :--> ");
	scanf("%d", &n);

	long int result = fact(n);
	printf("%d! = %ld", n, result);

	return 0;
}

Output:

Enter Number :--> 6
6! = 720

≪ Previous | Next ≫