Tuesday, July 27, 2010
Monday, July 26, 2010
Thursday, June 17, 2010
MATHEMATICS IS THE QUEEN OF ALL SCIENCES bcz
Wednesday, June 2, 2010
Friday, February 5, 2010
Sunday, October 4, 2009
Friday, August 7, 2009
RECURSION
RECURSION
Introduction
You can express most of the problems in the following program by using recursion. We represent the function add by using recursion.
Program#include
int add(int pk,int pm);
main()
{
int k ,i,m;
m=2;
k=3;
i=add(k,m);.
printf("The value of addition is %d\n",i);
}
int add(int pk,int pm)
{
if(pm==0) return(pk); \\ A
else return(1+add(pk,pm-1)); \\ B
}
Explanation
The add function is recursive as follows:add (x, y) = 1 + add(x, y-1) y > 0
= x y = 0
for example,
add(3, 2) = 1 + add(3, 4)
add(3, 1) = 1 + add(3, 0)
add(3, 0) = 3
add(3, 1) = 1+3 = 4
add(3, 2) = 1+4 = 5
The recursive expression is 1+add(pk, pm-1). The terminating condition is pm = 0 and the recursive condition is pm > 0.
Introduction
You can express most of the problems in the following program by using recursion. We represent the function add by using recursion.
Program#include
int add(int pk,int pm);
main()
{
int k ,i,m;
m=2;
k=3;
i=add(k,m);.
printf("The value of addition is %d\n",i);
}
int add(int pk,int pm)
{
if(pm==0) return(pk); \\ A
else return(1+add(pk,pm-1)); \\ B
}
Explanation
The add function is recursive as follows:add (x, y) = 1 + add(x, y-1) y > 0
= x y = 0
for example,
add(3, 2) = 1 + add(3, 4)
add(3, 1) = 1 + add(3, 0)
add(3, 0) = 3
add(3, 1) = 1+3 = 4
add(3, 2) = 1+4 = 5
The recursive expression is 1+add(pk, pm-1). The terminating condition is pm = 0 and the recursive condition is pm > 0.
Subscribe to:
Posts (Atom)






