Monday, October 10, 2011

Program:To find factorial of a number using recursion




When a function calls itself repeatedly, until some specified condition is met then this process is process is called as recursion.Lets have a program to find the factorial using recursion in c++.

CODE:

#include<iostream.h>
#include<conio.h> 
void main() 
{ 
Clrscr();
int fact(int); 
int f,n; 
cout<<"Enter the value to find factorial "; 
cin>>n; 
f=fact(n); 
cout<<"Factorial is "<<f<<endl; 
getch(); 
} 
int fact (int n) 
{ 
int value=1; 
if (n==1) 
return value;      // Base Case
else 
{ 
value=n*fact(n-1);   // General Case- Calls the function itself  
return value;            
}}

Article by
Chief-Editor

He is a tech Enthusiast, an Altruist and calm mentor. He loves to code. He is also a creative graphic designer. Do check out his designfolio @ Jasmeet.asia If you like This post, you can follow me on Twitter.



For Further Reading,
C++ Program, Functions, Recursion

1 comments:

raleyxi on March 3, 2022 at 11:14 PM said...

New York casinos, sports betting, hotel, gaming - DRMCD
New York's casinos and sports betting options are coming to a 김포 출장안마 real-time and 울산광역 출장안마 free online gaming destination. We look forward 순천 출장안마 to seeing you 과천 출장마사지 at 대전광역 출장안마

Post a Comment