Thursday, August 2, 2012

Calculate Factorial value using recursion

Q. Write a C program to accept any number from user and calculate its factorial value using recursion method.


Ans.


/*c program to find out factorial value using recursion method*/
#include<stdio.h>
#include<conio.h>
int fact(int );
int main()
{
  int num,res;
  printf("Enter any number: ");
  scanf("%d", &num);
  res = fact(num);
  printf("Factorial value is: %d",res);
  getch();
  return 0;
}
int fact(int n)
{
  int f;
  if(n==1)
     return(1);
  else
     f = n*fact(n-1);
  return(f);
}


/************Output************/


Output of calculate factorial value using recursion method C program
Screen shot for calculate factorial value using recursion method

No comments:

Post a Comment