Wednesday, October 2, 2013

Saturday, January 24, 2009

4th LEARNINGS OF THE WEEK 1 -Caligdong

HTML

HTML stands for Hyper Text Markup Language.An HTML file consists of small markup tags which tells the web browser hot to display the page. It is indicated by an "htm" or "html" file extension. it is created through notepad or other simple text editor applications.

The most important tags in HTML are those that define headings, paragraphs, and line breaks.
Here are list of some common tags:

TAG DESCRIPTION
< html > Defines an HTML document
< body > Defines the document's body
< h1 > to < h6 > Defines header 1 to 6

Defines a paragraph
< br / > Inserts a single line break
< hr / > Defines a horizontal rule
< !- - > Defines a comment
%nbsp; Adds one space
*tags for html text formatting*
defines inserted text
defines deleted text

Some characters like the <>

A character entity has three parts: an ampersand (&), an entity name or a # and an entity number, and finally a semicolon (;).

The less than sign must be written in this way:
&It; or <.

The advantage of using a name instead of a number is that a name is very easy to remember.
Here are the list of some common character entities:

result entity name entity number
< &It  
> > <
& & &
" &qout; "
' ' '
x × ×

÷ ÷ ÷


Friday, January 23, 2009

Learnings of the Week (CAMAY)

We had a lesson this week but we weren't able to discuss it.

It's all about ARRAYS. Array is a collection of variables of the same data type that is referenced by a common name.

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();
}

THE OUTPUT FOR THE EXAMPLE IS:

25 5 7 11 163


PARTS OF ARRAY

Array[0] = 25

"Array" is called the array name.
"[0]" is the subscript or index.
"25" is the array element.


* 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. It 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]


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

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

Learnings of the Week (CAMAY)

LOOPING


Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met. It can be predefined as in the loop, or open ended as in while and do-while.


The types of iterative statements are:

1. The For statements

2. The While statements

3. The Do-While statements


The For statement or for loop is considered as a predefined loop because the number or times it iterates to perform its body is predetermined in the loop’s definition.

The For loop contains a counter whose values determine the number of times the loop iterates. The iteration stops upon reaching the number of times specified in the loop.


The general form of the for statement is:

for (initialization; condition; increment)
{
statement_sequence;
}

Where:
--->for is a reserve word in C

--->initialization is an assignment statement that is used to set the loop’s counter.

--->condition is a relational boolean expression that determines when the loop will exit.

--->increment defines how the loop’s counter will change each time the loop is separated.

--->statement sequence may either be a single C statement or a block of C statements that make up the loop body.


~> The for loop continues to execute until the condition is True (1).
~> Once False (0), program execution resumes on the statement following the for loop.
~> Note:
a. Never place a semicolon right after the for header.

b. Never change the value of the for loop’s counter in side the body of the loop. This will affect the result of the program.

c. The increment part of the for loop is execute after the first iteration of the loop.


Example:
Write a program that will print the numbers 1 to 10 using a for statement.
#include
int x;
main()
{
for (x=1; x<=10; x++)
printf (“%d\n”,x);
getch();
}


[the output for this example is:]

1
2
3
4
5
6
7
8
9
10


----> The while statement or while loop is an open-ended or event-controlled loop.
The while loop iterates while the condition is TRUE (1).
When it becomes FALSE (0), the program control passes to the line after the loop code.

The general form of the while statement is:

while (condition)
{
statement_sequence;
}

where:
~> While is a reserved word in C

~> Condition is a relational expression that determines when the loop will exit.

~> Statement_sequence may either be a single C statement or a block of C statements that make up the loop body.


The second type of open-ended or event-controlled loop is the do-while statement or do-while loop.
The general form of the do-while statement is:
do
{
statement_sequence;
} while (condition);


~> Do-While is a variation of the while statement which checks the condition at the bottom / end of the loop.

~> This means that a do-while loop “always executes at least once”.

~> In the do-while loop, when the condition evaluates to TRUE (1), the loop body will be executed, but when FALSE (0), program control proceeds to the next instruction after the do-while loop.

Monday, January 19, 2009

3rd-learnings of the week(Colegado)

In computer science, an array is a data structure consisting of a group of elements that are accessed by indexing. In most programming languages each element has the same data type and the array occupies a contiguous area of storage.
Arrays permit constant time (O(1)) random access to individual elements, which is optimal, but moving elements requires time proportional to the number of elements moved. On actual hardware, the presence of e.g. caches can make sequential iteration over an array noticeably faster than random access — a consequence of arrays having good locality of reference because their elements occupy contiguous memory locations — but this does not change the asymptotic complexity of access. Likewise, there are often facilities (such as memcpy) which can be used to move contiguous blocks of array elements faster than one can do through individual element access, but that does not change the asymptotic complexity either.

Memory-wise, arrays are compact data structures with no per-element overhead. There may be a per-array overhead, e.g. to store index bounds, but this is language-dependent. It can also happen that elements stored in an array require less memory than the same elements stored in individual variables, because several array elements can be stored in a single word; such arrays are often called packed arrays.

Array is a collection of variables of the same data type that is referenced by a common name. The two declarations for arrays number and answer can be combined into a single declaration:
int number[100] , answer [25];
Arrays can give initial values during the declaration. This is called array initialization..
int Array1[5]={25, 5, 7, 11, 163};

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.

3rd-learnings of the week(Colegado)

RECURSION

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.


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.

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:

Enter a value: 5
The new value is 10.

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.

A common method of simplification is to divide a problem into subproblems of the same type. As a computer programming technique, this is called divide and conquer and is key to the design of many important algorithms, as well as being a fundamental part of dynamic programming.

Recursion in computer programming is exemplified when a function is defined in terms of itself. One example application of recursion is in parsers for programming languages. The great advantage of recursion is that an infinite set of possible sentences, designs or other data can be defined, parsed or produced by a finite computer program.

Recurrence relations are equations to define one or more sequences recursively. Some specific kinds of recurrence relation can be "solved" to obtain a non-recursive definition.

A classic example of recursion is the definition of the factorial function, given here in C code:

unsigned int factorial(unsigned int n)
{
if (n <= 1) return 1;
return n * factorial(n-1);
}

The function calls itself recursively on a smaller version of the input (n - 1) and multiplies the result of the recursive call by n, until reaching the base case, analogously to the mathematical definition of factorial.

Use of recursion in an algorithm has both advantages and disadvantages. The main advantage is usually simplicity. The main disadvantage is often that the algorithm may require large amounts of memory if the depth of the recursion is very large. It has been claimed that recursive algorithms are easier to understand because the code is shorter and is closer to a mathematical definition, as seen in these factorial examples.

It is often possible to replace a recursive call with a simple loop, as the following example of factorial shows:

unsigned int factorial(unsigned int n) {
if (n <= 1) return 1;
unsigned int result = n;
while (--n) result *= n;
return result;
}

It should be noted that on most CPUs the above examples give correct results only for small values of n, due to arithmetic overflow.

An example of a recursive algorithm is a procedure that processes (does something with) all the nodes of a tree data structure:

void ProcessTree(node x) {
unsigned int i = 0;
while (i < x.count) {
ProcessTree(x.children[i]);
i++;
}
ProcessNode(x); // now perform the operation with the node itself
}

To process the whole tree, the procedure is called with a root node representing the tree as an initial parameter. The procedure calls itself recursively on all child nodes of the given node (i.e. sub-trees of the given tree), until reaching the base case that is a node with no child nodes (i.e. a tree having no branches known as a "leaf").

A tree data structure itself can be defined recursively (and so predestinated for recursive processing) like this:

typedef struct {
unsigned int count;
node* children;
} node

Saturday, January 17, 2009

Learnings of the Week (CAMAY)

RECURSION

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.


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.

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:


Enter a value: 5
The new value is 10.



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.