Factorial of a number using recursion

source code:

 #include<stdio.h>
         int fact(int);
        int main()
   {
        int num,f;
        printf("\nEnter a number: ");
       scanf("%d",&num);
       f=fact(num);
       printf("\nFactorial of %d is: %d",num,f);
      getch();
      return 0;
  }

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

Comments

Popular posts from this blog

8086 STRING MANIPULATION –FIND AND REPLACE A WORD

Animated Circles In C++

C program to find out the sum of series 1 + 2 + …. + n.