_salibo

This week,

our lesson was all about 
ARRAY

It is a collection of variables of the same data type that is referenced by a common name.

Array declaration
-The general form for any declaration is as follows:

type array_name[size];

Where:
type is any valid data type in Turbo C which declares the type of values that array will hold.

array_name is a valid variable name which will name the array.

size defines how many elements the array will hold

-The two declarations for arrays number and answer can be combined into a single declaration:
int number[100] , answer [25];

Array Initialization
-Arrays can give initial values during the declaration. This is called array initialization..

int Array1[5]={25, 5, 7, 11, 163};

Saturday, January 17, 2009

_salibo

This week, I learned about RECURSION….


The repetitive process by which a function calls itself is called RECURSION OR CIRCULAR DEFINITION.

This is a way of defining something in terms of itself. 

A function is said to be recursive if a statement in the body of the function calls the function that contains it. 


PARTS OF THE RECURSIVE FUNCTION

Base Case 
This is the part of the recursive function that is found on the IF clause. This contains the condition that should be satisfied at one point of execution to terminate the repetitive process done by the recursive function. 

General Case 
This is the part of the recursive function that is found on the else-clause. This contains the function call of the recursive function to itself. 


EXAMPLE:

factorial (int n)

{
if (n == 1 || n == 0) return 1;
else return (n * factorial (n-1));
}

If the n value is 4, 4 * (factorial (4-1)
if the n value is 3, 3 * (factorial (3-1)
if the n value is 2, 2 * (factorial (2-1)
if the n value is 1, 1



DIRECT AND INDIRECT RECURSION

Direct recursions are recursive functions that can call itself through a function call directly inside the body of the function. 

Indirect recursions are recursive functions that can call another functions outside its function.

Friday, January 9, 2009

 
ziee ++ :] BLOG! - Wordpress Themes is proudly powered by WordPress and themed by Mukkamu Templates Novo Blogger