/*How to learn recursive function call in cpp/C++/C
Cpp Program to learn recursive function */
#include<iostream>
using namespace std;
int sum(int m, int k);
int main()
{
int i,m,k;
m=3;
k=2;
i=sum(m,k);
cout<<"sum="<<i<<endl;
//return 0;
}
int sum(int rm, int rk)
{
cout<<rm<<" "<<rk<<endl;
if(rm==0) return(rk);//termination condition
else return(1+sum(rk, rm-1));//recursive condition//if not +1 then sum=0
}
/*
3 2
2 2
2 1
1 1
1 0
0 0
sum=5 //in stack first address of sum(3,2) was stored
*/
Cpp Program to learn recursive function */
#include<iostream>
using namespace std;
int sum(int m, int k);
int main()
{
int i,m,k;
m=3;
k=2;
i=sum(m,k);
cout<<"sum="<<i<<endl;
//return 0;
}
int sum(int rm, int rk)
{
cout<<rm<<" "<<rk<<endl;
if(rm==0) return(rk);//termination condition
else return(1+sum(rk, rm-1));//recursive condition//if not +1 then sum=0
}
/*
3 2
2 2
2 1
1 1
1 0
0 0
sum=5 //in stack first address of sum(3,2) was stored
*/
for details one can refer to
ReplyDeletelearncppdotcom
and
linuxforudotcom