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



  1. include<iostream.h>
  1. include<conio.h>


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();

};
Tags: None

Comments
bout program - Posted on Monday, March 10, 2008 at 4:22 AM by mfarhan133
excellent program for begginers of understanding recursion
c++ - Posted on Tuesday, March 11, 2008 at 11:50 PM by xz116926
dd
dfsd
df
dfh
Tip - Posted on Tuesday, March 18, 2008 at 11:53 AM by Jonathan
Code would be much more readable if you put it in code tags ([code]...[/code]).


Sponsored links

Six Sigma Certification
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
PureCM Software Configuration Management
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
Experience Adobe? FLASH MEDIA SERVER 3
Introducing the media solution for total action without interruption. TRY IT NOW FOR FREE!


Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.