Thursday 23 January 2014

Filled Under:

/* WAP to find Factorial of a number using recursive function */

/* Factorial of a number using recursive function */

#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
    int num;

    printf("Enter A Number:");
    scanf("%d",&num);

    printf("\n%d!=%d",num,fact(num));

    getch();
}

fact(int num)
{
    if(num<1)
    {
        return 1;
    }
    else
    {
        return (num*fact(num-1));
    }
}

0 comments:

Post a Comment