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

#include<stdio.h>
#include<conio.h>
int factorial(int f)
{
    int fact;
    if(f==1)
        return(1);
    else
        fact=f*factorial(f-1);
    return(fact);
}
main()
{

    int n,r;
    clrscr();
    scanf("%d",&n);
    r=factorial(n);
    printf("%d",r);
    getch();
}
Next Post Previous Post
No Comment
Add Comment
comment url