Program Development Styles and Basics of C 19
Initialization: The variables involved in iteration process are initialized. These variables are used to
decide when to end the loop as per Fig. 1.24.
Decision: The decision variable is used to decide whether to continue or discontinue the loop.
When the condition is satisfied, control goes to return, else it goes to the computation block.
Computation: The required processing or computation is carried out in this block.
Update: The decision argument is changed and shifted to the next iteration.
Recursion
The loop which performs a repeated action of a set of instructions can be classified as either iterative
or recursive. Recursive loop is different from iterative loop. Recursion is the fundamental concept of
mathematical logic. In recursion the procedure may be direct or indirect as per Fig. 1.25. In direct
Fig. 1.24 Iterative processes
recursion the procedure calls itself. In addition, if the procedures call another procedure then it is an
indirect recursion. Recursion is the technique of defining a function or a process in terms of the
result of applying the same function to a simpler argument. A self-referencing conditional expression
is called a recursive procedure.
20 Programming and Data Structures
int
num ()
{
int
num();
}
a) Direct recursion
int nu m()
int sum() ;
}
int sum()
{
num () ;
}
b) Indirect recursion
Fig. 1.25 Types of recursion
Preliminary part
Body
Restore previously stored
local variables, formal
parameters and return
address.
End-part
Fig. 1.26 Recursive process
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.8.8