Write a Factorial Program using Recursion in C++

 Write a Factorial Program using Recursion in C++

What are recursive functions?

<!-w3school-> Recursive functions are those functions that repeatedly calls itself directly or indirectly during execution .
                          

                                          Steps to write the program

1. Open a turbo c++ compiler or any other compiler.

2. Write the code given below .


#include<iostream.h>
#include<conio.h>

int Factorial(int x)  // Factorial Function  Coding
{
 if(x<=1)
 { return 1; }
 else {  return x*Factorial(x-1); }
}
void main()      // Main Function Coding
{
clrscr();
int n;
cout<<"\nEnter the value of n";
cin>>n;
cout<<"\nThe factorial of the number    "<<n<<"is equal to   " <<Factorial(n);
getch();
}





OUTPUT:


Comments

Popular posts from this blog

Java Project Code: Cinema Ticket booking system : Create a Java Application to book a ticket in a Cinema hall.