|
Current area:
HOME -> Blogs -> mfarhan133's Blog -> Read Post |
recurrsion examples
|
Posted on Monday, March 10, 2008 at 4:21 AM
|
|||||||
|
// By muhammad farhan khan 20-02-08
int fact(int f) // f! { if(f==0) return 1; else return f*fact(f-1); } int fibonacci(int n) // series 1 1 2 3 5 8 13 sum of prev two nos { // in func n is the index no. if(n==1||n==2) return 1; else return fibonacci(n-1)+fibonacci(n-2); } double pow(int a,int b) // a^b { if(b==1) return a; else return a*pow(a,b-1); } int mul(int a,int b) // a*b //farhan production { if(b==1) return a; else return a+mul(a,--b); } int multiply(int a,int b) // sir rashid production { if(b==1) return a; else return a+multiply(a,--b); } int add(int a,int b) // a+b //farhan production { if(b==1) return ++a; else return 1+add(a,--b); } int sum(int a,int b) // sur rashid production { if(b==0) return a; else return sum(a+1,--b); } void main() { clrscr(); int a; char o; do { cout<<"\n enter the index no "; cin>>a; cout<<"\n Answer = "<<sum(4,a); cout<<"\n\n Do you want to continue (y/n) "; cin>>o; } while(o=='y'|| o=='Y'); getch(); };
|
Sponsored links
Six Sigma Certification
100% Online-Six Sigma Certificate from Villanova - Find Out More Now.
100% Online-Six Sigma Certificate from Villanova - Find Out More Now.
Virtual File System SDK
Create your own file systems in Windows and .NET applications
Create your own file systems in Windows and .NET applications
PureCM Software Configuration Management
Version control and integrated issue tracking - powerful and easy to use. Get your FREE trial now!
Version control and integrated issue tracking - powerful and easy to use. Get your FREE trial now!
Software Localization Tool Sisulizer
Localize DotNet, C++ Builder, Delphi, C/C++, Visual Basic & Java apps & html help. Try Sisulizer now
Localize DotNet, C++ Builder, Delphi, C/C++, Visual Basic & Java apps & html help. Try Sisulizer now
Experience Adobe? FLASH MEDIA SERVER 3
Introducing the media solution for total action without interruption. TRY IT NOW FOR FREE!
Introducing the media solution for total action without interruption. TRY IT NOW FOR FREE!