Write a program to find the factorial of the given number using function with recursion.

/* Write a program to find the factorial of the given number using function with recursion*/

#include <stdio.h>

long factorial(int);

void main()

{

    int n,f;

    printf("Enter the number : ");

    scanf("%d",&n);

    f=factorial(n);

    printf("Factorial = %ld\n",f);

    getch();

}

long factorial(int x)

{

    if (x<1)

    {

        return 1;

    }

    return x*factorial(x-1);

}

Comments

Popular posts from this blog

Write a program to accept numerator and denominator and find the remainder without using modulus (%) operator using do..while loop.