Friday, January 23, 2009

Learnings of the week-Navarra

ARRAYS


Single – Dimensional Arrays

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

l Example:

#include

main()

{

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

clrscr();

printf(“%d %d %d %d %d”, array[0], array[1], array[2],array[3],array[4]);

getch();

}

Parts of the array are:

Array[0] = 25

· Array name - Array

· Subscript or index - [0]

· Array element - 25

Array declaration

l 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.

l The two declarations for arrays number and answer can be combined into a single declaration:

int number[100] , answer [25];

Array Initialization

l Arrays can give initial values during the declaration. This is called array initialization..

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


Tuesday, January 20, 2009

LEARNINGS OF THE WEEK (M.N. SISON)

"ARRAYS"
SINGLE DIMENSIONAL ARRAYS

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

#include
main()
{
int array[4]={25,5,7,11,163};
clrscr();
printf(“%d %d %d %d %d”, array[0], array[1], array[2],array[3],array[4]);
getch();
}

Array declaration
lThe 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.

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


Array Initialization

l
lArrays can give initial values during the declaration. This is called array initialization..
l
int Array1[5]={25, 5, 7, 11, 163};




LEARNINGS OF THE WEEK (M.N. SISON)

We have discussed about programming:RECURSION
this is how we defined Recursion...

RECURSION


  • It is the repetitive process by which a functions 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 RECURSION:

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.

KINDS OF RECURSION:
Direct Recursions are recursive functions that can call itself through a function call directly inside the body of the function. v Indirect recursions are recursive functions that can call another functions outside its function.




Sunday, January 11, 2009

RECURSION - Joannacel Paraiso

RECURSION
  • l
    lThe repetitive process by which a functions calls itself is called recursion or circular definition.
  • lThis is a way of defining something in terms of itself.
  • lA function is said to be recursive if a statement in the body of the function calls the function that contains it.
Parts of 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.



factorial (int n)
{
if (n == 1 || n == 0) return 1;

else return (n * factorial (n-1));
}

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


factorial (int n)
{

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

Simplifying the Expression....

4 * (factorial (4-1) = 24 general case
3 * (factorial(3-1) = 6 general case
2 * (factorial(2-1) = 2 general case
1 base case

Therefore, the final return value when n=4 is 24.

Direct and Indirect Recursion
  • Direct recursions are cursive functions that can call itself through a functioncall directly inside the body of the function.
  • Indirect recursions are cursive functions that can call another functions outside the function.














Saturday, January 10, 2009

Recursion - Navarra

Our Christmas vacation is over. It is already a new year, thus we are entering a new lesson. It is not totally new because it is still programming but the lesson is harder than our past lessons. Last time, we discuss only the different conditions but now, we are focusing on a program that consist two or more functions aside from the main function. Isn’t in difficult???

Well, we have no choice but the study and remember the lessons that are being discussed to us because all of us want to pass this subject.


RECURSION is:

  • The repetitive process by which a functions 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.

Recursion also has its parts. And that are:

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.


There is also two kind of recursion. Those are the Direct and Indirect Recursio

  • Direct Recursions are recursive functions that can call itself through a function call directly inside the body of the function.
  • v Indirect recursions are recursive functions that can call another functions outside its function.

EXAMPLES:

1.

factorial (int n)

{

if (n == 1 || n == 0) return 1;

else return (n * factorial (n-1));

}

Simplifying the expression……

4 * (factorial (4-1) = 24 general case

3 * (factorial (3-1) = 6 general case

2 * (factorial (2-1) = 2 general case

1 base case

Therefore, the final return value when n=4 is 24.

2.

Give the output of the ff. program when the value entered for a=5.

#include

main()

{

int a, b;

clrscr();

printf(“Enter a value:”);

scanf(“%d”, &a);

b= solve (a);

printf(“The new value is %d”, b);

getch();

}

solve (int a)

{
if (a = = 1) return 2;

else return (solve (a-1) + 2);

}

The output is 10.