Q:

Factorial of a Number In C Using Recursion

belongs to collection: Recursion Programs In C

0

Factorial of a Number In C Using Recursion

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Factorial of a Number In C Using Recursion

Algorithm

  • Program Start
  • Declaring Variable
  • Input Number From the user
  • Calling Recursive Function
  • Display Result Through Printf Function
  • Program End

Program

//Factorial of a Number In C Using Recursion

#include<stdio.h>
int fact(int );
void main()
{ //variable declaration
  int x,z;
  
  //input number
  printf("Enter a number : ");
  scanf("%d",&x);
  
  z=fact(x); //calling recursive function to find factorial
  printf("factorial is %d",z);
}
int fact(int n)
{   int ft=1;
    if(n==1)
    return(n);
    ft=n*fact(n-1);
    return(ft);
}

Output

Enter a number : 5
factorial is 120

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Prime Number Program In C Using Recursion... >>