Interview Questions   Tutorials   Discussions   Programs   

C - Write a program that finds the factorial of a number using recursion?




334
views
asked marvit August 18, 2014 09:50 AM  

Write a program that finds the factorial of a number using recursion?


           

1 Answers



 
answered By bhjahnavi   0  
recursion:
    the term recursion in c means repeatedly calling a function.

/*program to find factorial of a number using recursion*/
#include<stdio.h>
int factorial(int n);
int main()
{
  int n;
  printf("Enter an positive integer: ");
  scanf("%d",&n);
  printf("Factorial of %d = %ld", n, factorial(n));
  return 0;
}
int factorial(int n)
{
  if(n!=1)
   return n*factorial(n-1);
}
output:
 Enter an positive integer: 6
Factorial of 6 = 720


flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert