Write a C program to calculate factorial of a number using recursion. - Pratik Ghelani

Pratik Ghelani

Breaking

Friday, March 29, 2019

Write a C program to calculate factorial of a number using recursion.

Write a C program to calculate factorial of a number using recursion.

Program:-

#include <stdio.h>
mul(int n);
int main()
{
    int n;
    printf("Enter a positive integer: ");
    scanf("%d", &n);
    printf("Factorial of %d = %ld", n, mul(n));
    return 0;
}
mul(int n)
{
    if (n >= 1)
        return n*mul(n-1);
    else
        return 1;

}


Output:-


No comments:

Post a Comment