C Program To Find Factorial Of Number


Aim :- Write a C Program To Find Factorial Of Number Using Recursion.


For any positive number n, it's factorial is given by:
factorial = 1*2*3...*n
Factorial of negative number cannot be find.
Factorial of 0 is 1.


C Program Code :


#include <conio.h>
#include <iostream.h>
int fact(int);
void main()
{
      int f,n;
      clrscr();

      printf("Enter the number : ");
      scanf("%d",&n);
      f=fact(n);
      printf("Factorial = %d",f);
      getch();
}

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


Output :


Post a Comment

0 Comments