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

item