C Program to Calculate Factorial of a Number Using Recursion

#include<stdio.h>
#include<conio.h>

int factorial(int);

void main()
{
    int n;
    printf("Enter a number: ");
    scanf("%d",&n);
    printf("Factorial of %d is %d",n,factorial(n));
    getch();
}

int factorial(int n)
{
    if(n==0)
        return 1;
    else
        return (n*factorial(n-1));
}

OUTPUT:

No comments:

Post a Comment