Saturday, October 18, 2008

Learnings of the Week - October 18, 2008


ITERATIVE STATEMENTS


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 For Statements

- is considered as a predefined loop because the number or times it iterates to perform its body is predetermined in the loop’s definition

- 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

- 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


The While Statement

- 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

- 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 Do-While Statement


- the second type of open-ended or event-controlled loop

- while and do are reserved words 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 C statements that make up the loop body

- Is a variation of the while statement which checks the condition at the bottom / end of the loop

- This means that “always executes at least once”

- 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



Posted by:
RAE ANGELINE S. PALEN

Thursday, October 16, 2008

LEARNINGS OF THE WEEK

by: Hanna Deborrah T. Onking



This week, I have learned about the iterative statements.


ITERATIVE STATEMENTS

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.

Types of Iterative Statements

l The For statements

l The While statements

l The Do-While statements


For Statements

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

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


l The general form of the for statement is:

for (initialization; condition; increment)

{

statement_sequence;

}


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.

While statement

l The while statement or while loop is an open-ended or event-controlled loop.

l The while loop iterates while the condition is TRUE (1).

l When it becomes FALSE (0), the program control passes to the line after the loop code.


l The general form of the while statement is:

while (condition)

{

statement_sequence;

}


The do-while statement


}

l The second type of open-ended or event-controlled loop is the do-while statement or do-while loop.

l The general form of the do-while statement is:

do

{

statement_sequence;

} while (condition);


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

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

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

^^Learnings of the Week

Submitted to:
Joyce Niko D. Perez
IV- RIZAL

ITERATIVE STATEMENTS

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.


Types of Iterative Statements

l The For statements

l The While statements

l The Do-While statements


For Statements

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

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


l The general form of the for statement is:

for (initialization; condition; increment)

{

statement_sequence;

}


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.

While statement

l The while statement or while loop is an open-ended or event-controlled loop.

l The while loop iterates while the condition is TRUE (1).

l When it becomes FALSE (0), the program control passes to the line after the loop code.


l The general form of the while statement is:

while (condition)

{

statement_sequence;

}


The do-while statement


}

l The second type of open-ended or event-controlled loop is the do-while statement or do-while loop.

l The general form of the do-while statement is:

do

{

statement_sequence;

} while (condition);


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

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

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

Saturday, October 11, 2008

LEARNINGS OF THE WEEK ( October 11)

by: Hanna Deborrah T. Ongking


This week, we have discussed about the conditional statements and we are having a series of programming activities for us to understand more.



CONDITIONAL STATEMENTS

Conditional statements are statements that check an expression then may or may not execute a statement or group of statement depending on the result of the condition.


TYPES OF CONDITIONAL STATEMENTS

The If Statement

- the expression is relational or Boolean expression that evaluates to a TRUE (1) or FALSE (0) value

- statement may either be a single or a block of C statements

- if the expression evaluates to TRUE (1), the statement or the blockof statements that forms the target of the if statement will be executed. Otherwise, the program will ignore the statement or the block of statements


The If-Else Statement

- if and else are reserved words

- expression is relational or Boolean expression that evaluates to a TRUE (1) or False (0) value

- statement_1 and statemenr_2 may either be a single C statement or a block of C statements

- if the expression is TRUE (1), the statement or block of statement after the if statement will be
executed; otherwise, the statement or block of statement in the else statement will be executed

- only the code associated with the if or the code that is associated with the else executes, never both


The Nested-If Statement

- one of the most confusing aspects of the if statement in any programming language is nested ifs

- is an if statement that is the object of either an if or else

- this is sometimes referred to as “an if within an if”

- it can be difficult to know what else associates with what if

- C provides a very simple rule for resolving this type of situation

- in C, the else is linked to the closest preceding if that does not already have an else statement associated with it


The If-Else-If Ladder

- a common programming construct in C

- are reserved words in C

- the expression are evaluated from the top downward

- as soon as a true condition is found, the statement associated with it is executed and the rest of the ladder will not be executed

- if none of the condition is true, the final else is executed

- the final else acts as a defaults condition

- if all other conditions are false, the last else statement is performed

- if the final else is not present, then no action takes place

- note that the final else is optional, you may include this part if needed in the program or you may not include if not needed


The Switch Statement

- is a multiple-branch decision statement

- a variable is successively tested against a list or integer or character constants

- if a match is found, a statement or block of statement is executed

- the default part of the switch is executed if no matches are found

- according to Herbert Schildt, there are three important things to know about switch statements:

1. The switch differs from if statements in such a way that switch can only test for equality whereas if can evaluate a relational or logical expression

2. No two case constants in the same switch can have identical values. Of course, a switch statement enclosed by an outer switch may have case constant that are the same.

3. If character constants are used in the switch, they are automatically converted to their integer values.

- Note that the break statement is used to terminate the statement associated with each case constant. It is a C keyword which means that at that point of execution, you should jump to the end of the switch statement by the symbol }.


The Nested Switch Statement

Learnings of the Week - October 11, 2008

CONDITIONAL STATEMENTS

Conditional statements are statements that check an expression then may or may not execute a statement or group of statement depending on the result of the condition.


TYPES OF CONDITIONAL STATEMENTS

The If Statement


- the expression is relational or Boolean expression that evaluates to a TRUE (1) or FALSE (0) value

- statement may either be a single or a block of C statements

- if the expression evaluates to TRUE (1), the statement or the blockof statements that forms the target of the if statement will be executed. Otherwise, the program will ignore the statement or the block of statements


The If-Else Statement


- if and else are reserved words

- expression is relational or Boolean expression that evaluates to a TRUE (1) or False (0) value

- statement_1 and statemenr_2 may either be a single C statement or a block of C statements

- if the expression is TRUE (1), the statement or block of statement after the if statement will be
executed; otherwise, the statement or block of statement in the else statement will be executed

- only the code associated with the if or the code that is associated with the else executes, never both


The Nested-If Statement

- one of the most confusing aspects of the if statement in any programming language is nested ifs

- is an if statement that is the object of either an if or else

- this is sometimes referred to as “an if within an if”

- it can be difficult to know what else associates with what if

- C provides a very simple rule for resolving this type of situation

- in C, the else is linked to the closest preceding if that does not already have an else statement associated with it


The If-Else-If Ladder

- a common programming construct in C

- are reserved words in C

- the expression are evaluated from the top downward

- as soon as a true condition is found, the statement associated with it is executed and the rest of the ladder will not be executed

- if none of the condition is true, the final else is executed

- the final else acts as a defaults condition

- if all other conditions are false, the last else statement is performed

- if the final else is not present, then no action takes place

- note that the final else is optional, you may include this part if needed in the program or you may not include if not needed


The Switch Statement

- is a multiple-branch decision statement

- a variable is successively tested against a list or integer or character constants

- if a match is found, a statement or block of statement is executed

- the default part of the switch is executed if no matches are found

- according to Herbert Schildt, there are three important things to know about switch statements:

1. The switch differs from if statements in such a way that switch can only test for equality whereas if can evaluate a relational or logical expression

2. No two case constants in the same switch can have identical values. Of course, a switch statement enclosed by an outer switch may have case constant that are the same.

3. If character constants are used in the switch, they are automatically converted to their integer values.

- Note that the break statement is used to terminate the statement associated with each case constant. It is a C keyword which means that at that point of execution, you should jump to the end of the switch statement by the symbol }.


The Nested Switch Statement

Posted by:

RAE ANGELINE S. PALEN



Friday, October 10, 2008

LEARNINGS OF THE WEEK

By: Hanna Deborrah T. Ongking

This week, we still have series of activities in programming using the turbo. We usually use scanf in programming. But now, let’s see how it works.

The scanf function allows you to accept input from standard in, which for us is generally the keyboard. The scanf function can do a lot of different things, but it is generally unreliable unless used in the simplest ways. It is unreliable because it does not handle human errors very well. But for simple programs it is good enough and easy-to-use.

The simplest application of scanf looks like this:

scanf("%d", &b);

The program will read in an integer value that the user enters on the keyboard (%d is for integers, as is printf, so b must be declared as an int) and place that value into b.

The scanf function uses the same placeholders as printf:

  • int uses %d
  • float uses %f
  • char uses %c
  • character strings (discussed later) use %s

You MUST put & in front of the variable used in scanf. The reason why will become clear once you learn about pointers. It is easy to forget the & sign, and when you forget it your program will almost always crash when you run it.

In general, it is best to use scanf as shown here -- to read a single value from the keyboard. Use multiple calls to scanf to read multiple values. In any real program, you will use the gets or fgets functions instead to read text a line at a time. Then you will "parse" the line to read its values. The reason that you do that is so you can detect errors in the input and handle them as you see fit.

The printf and scanf functions will take a bit of practice to be completely understood, but once mastered they are extremely useful.

Submitted by:

Joyce Niko D. Perez

IV- RIZAL

CONDITIONAL STATEMENTS

Conditional Statements

l Are statements that check an expression then may or may not execute a statement or group of statement depending on the result of the condition.

Types of Conditional Statements:

l The If Statement

Expression is relational or Boolean expression that evaluates to a TRUE (1) or False (0) value.

l The If-Else Statement

The general form of the if-else statement is:

If (expression)

statement_1;

else

statement_2;

l The Nested-If Statement

l One of the most confusing aspects of the if statement in any programming language is nested ifs. A nested if is an if statement that is the object of either an if or else.

l This is sometimes referred to as “an if within an if.”

l The reason that nested ifs are so confusing is that it can be difficult to know what else associates with what if.

l The If-Else-If Ladder

l A common programming construct in C is the if-else- if ladder.

l The general form of the if-else-if ladder statement is:

if ( expression_1)

statement_1;

else if (expression_2)

statement_2;

else if (expression_3;

statement_3;

:

:

else

statement_else;

l The Switch Statement

l The switch statement is a multiple-branch decision statement.

l The general form of the switch statement is:

switch (variable)

{

case constant1:

statement sequence_1;

break;

case constant2:

statement_sequence_2;

break;

:

:

default:

statement_sequence_default;

}

l The Nested Switch Statement

l The general form of the nested switch statement is:

switch (variable)

{

case constant:{

switch (variable)

{

case constant1:

statement sequence_1;

break;

case constant2:

statement_sequence_2;

break;

}

break;

}

case constant2:

statement sequence;

break;

default:

statement sequence;

}

Saturday, October 4, 2008

learnings of the week (October 4)

By: Hanna Deborrah T. Ongking

we didn't discussed anything this week because we are very busy about our sciene investigatory projects and our dost scholarship. Sir Pete have excused us from all our subjects. aside from that, there are also science and math activities.

Learnings of the Week - October 4, 2008

STRUCTURE OF A SIMPLE C PROGRAM

#include
#define directive
main()
{
variable declaration section;
______________________
______________________
}

#include directive – contains information needed by the program to ensure the correct operation of C’s Standard library functions

#define directive – used to shorten the keywords in the program

Variable declaration section – it is the place where you declare your variables

Body of the program – start by typing main() and the { and }. All statements should be written inside the braces.

C is a case sensitive program, therefore use lowercase letters only.

COMMONLY USED INCLUDE FILES IN C LANGUAGE

alloc.h
- declares memory management functions


conio.h
- declares various functions used I calling IBM-PC ROM BIOS


ctype.h
- contains information used by the classification and character convertion macros


math.h
- declares prototype for the math functions


stdio.h
- defines types and macros needed for standard I/O


string.h
- declares several string manipulation and memory manipulation routines



IMPORTANT SYMBOLS

\n
- is a line char used to move the cursor to the next line


‘ ‘
- single quote is used for single character / letter


“ “
- double quote is used for two or more character


{
- open curly brace signifies begin


}
- close curly brace signifies end


&
- address of operator


*
- indirection operator / pointer



INPUT AND OUTPUT STATEMENTS


INPUT STATEMENT
A statement used to input a single character or a sequence of characters from the keyboard.


TYPES OF INPUT STATEMENT

getch
- a function used to input a single character from the keyboard without echoing the character on the monitor.


getche
- a function used to input a single character from the keyboard, the character pressed echoed on the monitor, line the READLN in PASCAL.


getchar
- a function used to input a single character from the keyboard, the character pressed echoed on the monitor terminated by pressing Enter key.


gets
- a function used to input a single character from the keyboard, spaces are accepted, terminated by pressing Enter key.


scanf
- a function used to input a single character or sequence of characters form the keyboard, it needs the control string codes in able to recognized. Spaces are not accepted upon inputting. Terminated by pressing spacebar.



OUTPUT STATEMENT
A statement used to display the argument list or string on the monitor.

TYPES OF OUTPUT STATEMENT

printf
- a function used to display the argument list on the monitor. It sometimes needs the control string codes to help display the remaining argument on the screen.


putchar
- a function used to display the argument list or string on the monitor. It is like overwriting a character


puts
- a function used to display the argument list or string on the monitor. It does not need the help of the control string codes.


FORMAT STRING AND ESCAPE SEQUENCE
All format specifiers start with a percent sign (%) and are followed by a single letter indicating the type of data and how data are to be formatted.

%c
- used for single char in C


scanf(“%c”, &ch);
printf(“%c”, ch);



%d
- decimal number (whole number)


scanf(“%d”,&num);
printf(“%d”,num);



%e
- scientific notation / exponential form


scanf(“%e” &result);
printf(“%e”, result);



%f
- number with floating or decimal point


scanf(“%f”,&pesos); printf(“%f”,pesos);


%o
- octal number


scanf(“%0”, &value);
printf(“%o”, value);



%s
- string of characters


scanf(“%s”,&str);
printf(“%s”,str);



%u
- unsigned number


scanf(“%u”, &value);
printf(“%u”, value);



%x
- hexadecimal numbers


scanf(“%x”,&value);
printf(“%x”,value);



%X
- capital number for hexadecimal number


scanf(“%X”, &nos);
printf(“%X”, nos);



%%
- print a percent sign


scanf(“%%”,%value);
printf(“%%”,value);



LIST OF COMMONLY USED ESCAPE SEQUENCE

\\
- prints backslash


\’
- prints single quotes


\”
- prints double quotes


\?
- prints question mark


\n
- newline


GOTOXY
A function gotoxy is used to send the cursor to the specified location.


INSERTING COMMENT
/*y is assigned a numeric literal*/


ASSIGNMENT STATEMENT
It stores a value or a computational result in a variable. They are commonly used to perform most arithmetic operations in program. It can also be used in printf() statement.

A format specifier %.2f can be used to limit the output being displayed into two decimal places only.



Posted by:
RAE ANGELINE S. PALEN

Thursday, October 2, 2008

^^Learnings of the Week

Submitted by:
Joyce Niko D. Perez
IV- RIZAL

INPUT and OUTPUT Statements

Input statements

n A statement used to input a single character or a sequence of characters from the keyboard.

Types of Input Statements:

o getch

o A function used to input a single character from the keyboard without echoing the character on the monitor.

o Syntax: getch();

o Example: ch = getch();

o getche

o A function used to input a single character from the keyboard, the character pressed echoed on the monitor, line the READLN in PASCAL

o Syntax: getche();

o Example: ch = getche();

o getchar

o A function used to input a single character from the keyboard, the character pressed echoed on the monitor terminated by pressing Enter key.

o Syntax: getchar();

o Example: ch = getchar();

o gets

o A function used to input a single character from the keyboard, spaces are accepted, terminated by pressing enter key.

o Syntax: gets();

o Example: gets(ch);

o scanf

o A function used to input a single character or sequence of characters from the keyboard, it needs the control string codes in able to recognized. Spaces are not accepted upon inputting. Terminated by pressing spacebar.

o Syntax: gets();

o Example: gets(ch);

Output Statements

o A statement used to display the argument list or string on the monitor.

Types of Output Statements:

o printf

o A function used to display the argument list on the monitor.

o It sometimes needs the control string codes to help display the remaining argument on the screen.

o Syntax: printf(“control string codes”, argument list)

o Example: printf(“Hello, %d, you are % years old.”, name, age);

o putchar

o A function used to display the argument list or string on the monitor. It is like overwriting a character.

o Syntax: putchar();

o Example:putchar(tolower(ch));

o puts

o A function used to display the argument list or string on the monitor. It does not need the help of the control string codes.

o Syntax: puts();

o Example: puts(“hello”);

Format String and Escape Sequence

o All format specifiers start with a percent sign (%) and are followed by a single letter indicating the type of data and how data are to be formatted.

List of Commonly used escape sequence:

o \\ - prints backslash

o \’ – prints single quotes

o \” – prints double quotes

o \? – prints question mark

o \n - newline

Gotoxy

o A function gotoxy is used to send the cursor to the specified location.

o Syntax: gotoxy(x,y);

o Example: gotoxy(5,10);

Inserting Comment

o /*y is assigned a numeric literal*/

Assignment Statement

o It stores a value or a computational result in a variable. They are commonly used to perform most arithmetic operations in a program. It can also be used in printf() statement.

o Syntax: variable = expression

o Example: y=1;