Program:

#include<stdio.h>
int fact(int n){
    int f;
    if(n == 1) return 1;
    f = n * fact (n-1);
    return f;
}
int main()
{
    int k,x;
    printf("Enter a number: ");
    scanf("%d",&x);
    k = fact(x);
    printf("Factorial of %d is: %d\n",x,k);
    return 0;
}

Output:

Enter a number: 5
Factorial of 5 is: 120

Leave a Reply

Your email address will not be published. Required fields are marked *