C Program to Find Factorial of Number Using Recursion

C Program to Find Factorial of Number Using Recursion:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

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

int fact(int); //Prototyping
main()
{
   int factorial,num;

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

   factorial=fact(num);
   printf("Factorial is %d",factorial);
}

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

OUTPUT:

Enter Number :5
Factorial is 120

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.