Thursday 7 March 2019

Write a Factorial Program using Recursion in C++

                    Program of Factorial using Recursion in C++

What are recursive functions?

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:


2 comments:

DBMS NOTES UNIT 3

                                                              UNIT 3  ER (Entity Relationship) An entity-relationship model is known as an E...