Compare Iterative and Recursive Functions?


ITERATIVE FUNCITONS

RECURSIVE FUNCTIONS
  A)
The process is repeated until a condition is satisfied

   A)
The  function repeatedly calls itself till the terminating condition is satisfied.
  B)
The sts included in the loo are executed repeatedly

   B)
The intermediate results are stored on to the stalk each time the function recursively called
  C)
Each time the loop is executed, the intermediate results are refined

   C)
The final value will be evaluated often retrieving the values stored on the stack

Ex: int gcd ( int a, int b)
{
int r;
r = a%b;
while ( r!=0)
{
a=b;
b=r;
r=a%b;
}
return b;
}

Ex: int gcd ( int a, int b)
{
int r;
r =a%b;
if ( r==0)
return b;
else
gcd ( b,r);
}

Related

C Language 4513749704322932219

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item