Programming

Program to Calculate the Factorial Using Recursion

Write a Program to Calculate the Factorial of Entered No. Using Recursion. Calculate the Factorial Using Recursion

Algorithm

  • Start
  • Enter a number-a
  • fact( n){
    if(n<=1){
    return 1;
    }else
    {
    return n*fact(n-1);
  • print Factorial=fact(a)
  • Stop

Source Code

#include<iostream.h>
#include<conio.h>
int fact(int);
void main(){
 int a;
 clrscr();
 cout<<"Enter a number: ";
 cin>>a;
 cout<<"Factorial= "<<fact(a);
 getch();
}

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

Tuts

About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.