Saturday, September 27, 2008

LEARNINGS OF THE WEEK (TAGARO)

LEARNINGS OF THE WEEK
BY: Sharra Mae S. Tagaro IV- Rizal
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 Statement
1.)The If Statement
2.)The If-Else Statement
3.)The Nested-If Statement
4.)The If-Else-If Ladder
5.)The Switch Statement
6.)The Nested Switch Statement

1.)The If Statement
l*The general form of the If statement is:
if ( expression)
statement;
-Expression is relational or Boolean expression that evaluates to a TRUE (1) or False (0) value.
- Statement may either be a single C statement or a block of C statements.
*
The general form of the If statement with block statement is:
if ( expression)
{
statement_sequence;
}
-In an if statement, if the expression evaluates to TRUE (1), the statement or the block of statements that forms the target of the if statement will be executed. Otherwise, the program will ignore the statement or the block of statements.

l
2.) The If-Else statement
*The general form of the if-else statement is:
If (expression)
statement_1;
else
statement_2;
l-Where:
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 statement_2 may either be a single C statement or a block of C statements.
l*The general form of the if-else statement with block of statement is:
If (expression)
{ statement_sequence;
}
else
{
statement_sequence;
}
l-If an if-else statement, 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.
lNote: Only the code associated with the if or the code that is associated with the else
executes,
never both.
l

3.)Nested-If statement
-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.
-In C, the else is linked to the closest preceding if that does not already have an else statement associated with it.
l*Consider the following situations:
Situations 1. The else at number 3 is paired with the if in number 2 since it is the nearest if statement with the else statement.
l1. if…..
l2. if ……
l3. else
Situations 2. The else in number 5 is paired with the if in number 1.
l1. if ….
l2. {
l3. if ….
l4. }
l5. else
l-Note that there is a pair of braces found in number 2 and number 4.
l-The pair of braces defined the scope of the if statement in number 1 starting from the { in number 2 and ends with } in number 4.
l-Therefore, the else statement in number 5 cannot paired with the if statement in number 3 because the else statement is outside the scope of the first if statement.
l-This makes the if statement in number 1 the nearest if statement to the else statement in
number 5.

4.)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-Where:
If and else are reserve words in C
Expression_1, expression_2 up to expression_n in relational or boolean expression that evaluates to a TRUE (1) or False (0) value.
Statement_1, statement_2 up to statement_else may either be a single C statement or a block
of C statement.
l-In an if-else-if ladder statement, the expression are evaluated from the top downward.
l-As soon as a true condition is found, the statement associated with it is executed and the rest of
lthe ladder will not be executed. If none of the condition is true, the final else is executed.
l-The final else acts as a defaults condition. If all other conditions are false, the last else
statement is performed.
l-If the final else is not present, then no action takes place.
lNote: The final else is optional, you may include this part if needed in the program or you may
not include if not needed.

5.)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-In a switch statement, a variable is successively tested against a list or integer or character
constants.
l-If a match is found, a statement or block of statement is executed.
l-The default part of the switch is executed if no matches are found.
l-According to Herbert Schildt (1992), 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 fro 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: The break statement is used to terminate the statement associated with each case constant. It is a C keyword which means that at the point of execution, you should jump to the end of the switch statement by the symbol }.


6.)The Nested Switch Statement
*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, September 20, 2008

LEARNINGS OF THE WEEK (TAGARO)

STRUCTURE OF A SIMPLE C PROGRAM
BY: Sharra Mae S. Tagaro IV- Rizal


This week, we discussed more about C language- specifically its structure.

Structure of a simple C program
#include
#define directive
main()
{
variable declaration section;
______________________
______________________
}
  • n#include directive – contains information needed by the program to ensure the correct operation of C’s Standard library functions.
  • n#define directive – used to shorten the keywords in the program.
  • nVariable declaration section – it is the place where you declare your
variables.
  • nBody of the program – start by typing main() and the { and }. All statements
should be written inside the braces.
Commonly used include files in C language.
  • nalloc.h – declares memory management functions.
  • nconio.h – declares various functions used in calling IBM-PC ROM BIOS.
  • nctype.h – contains information used by the calssification and character convertion macros.
  • nmath.h – declares prototype for the math functions.
  • nstdio.h – defines types and macros needed for standard I/O.
  • nstring.h – declares several string manipulation and memory manipulation routines.
Important Symbols
  • n\n – is a line char used to move the cursor to the next line
  • n‘ ‘ – single quote is used for single character / letter.
  • n“ “ – double quote is used for two or more character
  • n{ - open curly brace signifies begin
  • n} – close curly brace signifies end
  • n& - address of operator
  • n* - indirection operator / pointer


LEARNINGS OF THE WEEK (TAGARO)

INPUT AND OUTPUT STATEMENTS
BY: Sharra Mae S. Tagaro IV- Rizal
Input Statement
A statement used to input a single character or a sequence of characters from the keyboard.
Types of Input Statement

1.)getch
-A function used to input a single character from the keyboard without echoing the character on the monitor.
Syntax: getch();
o2.)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
oSyntax: getche();
o3.)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.
oSyntax: getchar();
o4.)gets
o-A function used to input a single character from the keyboard, spaces are accepted, terminated by pressing enter key.
oSyntax: gets();
o5.)scanf
oA 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 space bar.
oSyntax: gets();

Output Statement
A statement used to display the argument list or string on the monitor.
Types of Output Statement
1.)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.
Syntax: printf(“control string codes”, argument list)
o2.)putchar
o-A function used to display the argument list or string on the monitor. It is like overwriting a character.
oSyntax: putchar();
o3.)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.
oSyntax: puts();

Format String and Escape Sequence
Format Specifiers
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 format specifiers
1.)%c – used for single char in C
2.)%d – decimal number (whole number)
o3.)%e – scientific notation / exponential form
o
o
o4.)%f – number with floating or decimal point
o
o5.)%o – octal number
o
o
o6.)%s– string of characters
7.)%u – unsigned number
8.)%x– hexadecimal numbers
9.)%X – capital number for hexadecimal number
10.)%%– print a percent sign
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.
Syntax: gotoxy(x,y);
Example: gotoxy(5,10);
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 a program. It can also be used in printf() statement.
Syntax: variable = expression
Example: y=1;
Note:
A format specifier %.2f can be used to limit the output being displayed into two decimal places only.

LEARNINGS OF THE WEEK (TAGARO)

Learnings of the week
By: Sharra Mae S. Tagaro IV- Rizal
VARIABLES, CONSTANTS, OPERATORS AND EXPRESSION
- Identifiers are composed of a sequence of letters. Digits, and the special character _ (underscore).
- Avoid using names that are too short or too long.
- Limit the identifiers from 8 to 15 characters only.

Rules for defining or naming identifiers
- It must consist only of letters, digits, and underscore.
- Example: _duh, num_1 (correct)
- It should not begin with a digit.
- Example: 1name, 3to3 (incorrect)
- An identifier defined in the C standard library should not be redefined.
- Example: printf, scanf (incorrect)
- It is case sensitive; meaning uppercase is not equal to the lowercase.
- Example: ans != Ans != aNs
- Do not include embedded blanks.
- Example: large num (incorrect)
- Do not use any of the C language keywords as your variable/ identifier.
- Do not call your variable / identifier by the same name as other functions.

Variable Declaration
- All variables must be declared before they may be used. The general form of declaration is shown here:
Type variable list;
Example: int i,j, k;
short i,j,k;
- Note: Before declaring variables, specify first the data type of the variable/s.
- Variables must be separated by comma.
- All declarations must be terminated by a semicolon (;).

Two kinds of variables
- Local Variables - Variables that are declared inside a function are called local variables. It can only be referenced by statements that are inside the block in which the variables are declared.

- Global Variables - Global variables are known throughout the entire program and may be used by any piece of code. Global variables are created by declaring them outside of any function.

- Constants are identifier / variables that can store a value that cannot be changed during program execution.
- Example: const int count = 100;
- Where integer count has a fixed value of 100.

Arithmetic, Logical, Relational, and Bitwise Operations
- Operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
- There are three classes of operators in C: arithmetic, logical and relational, and bitwise.

Arithmetic Operators
Operator Action
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus Divisor
-- Decrement a value
++ Increment a value

Relational and Logical Operators
- In the term relational operator, the word relational refers to the relationship values can have with one another.
- In the term logical operator, the word logical refers to the ways these relationships can be connected together using the rules of formal logic.

Relational Operators

Operators Action
> Greater than
>= Greater than or equal to
<>
<= Less than or equal to
== equal
!= Not equal

Logical Operators

Operators Action Truth Table
&& AND true && true = true
true && false = false
false && true = false
false && false = false

OR true true = true
true false = true
false true = true
false false = false

! NOT !true = false
!false = true

Bitwise Operator
- Bitwise operators are the testing, setting or shifting of the actual bits in a byte or a word, which corresponds to C’s standard char and int data types and variants.
- Bitwise operators cannot by used on type float, double, long double, void or other more complex types.

The ? Operator
? Operator is a very powerful and convenient operator that can be used to replace certain statements of the if-then-else form.
- Example: y= x > 9 ? 100: 200
is equivalent to
If (x>9)
y=100;
Else
Y=200;

Evaluation of Expression
- Expression refers to anything that evaluates to a numeric value.

Order of Precedence
()
!, unary +, -
*. /. %
binary + , -
<, <=, >, >=
==, !=
&&

Thursday, September 18, 2008

Learnigns of the Week (ROLLORATA)

VARIABLES, CONSTANTS, OPERATORS AND EXPRESSION

- Identifiers are composed of a sequence of letters. Digits, and the special character _ (underscore).
- Avoid using names that are too short or too long.
- Limit the identifiers from 8 to 15 characters only.

* Variables are identifiers that can store a changeable value. These can be different data types.


Rules for defining or naming identifiers
- It must consist only of letters, digits, and underscore.
- Example: _duh, num_1 (correct)
- It should not begin with a digit.
- Example: 1name, 3to3 (incorrect)
- An identifier defined in the C standard library should not be redefined.
- Example: printf, scanf (incorrect)
- It is case sensitive; meaning uppercase is not equal to the lowercase.
- Example: ans != Ans != aNs
- Do not include embedded blanks.
- Example: large num (incorrect)
- Do not use any of the C language keywords as your variable/ identifier.
- Do not call your variable / identifier by the same name as other functions.

Variable Declaration
- All variables must be declared before they may be used. The general form of declaration is shown here:
Type variable list;
Example: int i,j, k;
short i,j,k;
- Note: Before declaring variables, specify first the data type of the variable/s.
- Variables must be separated by comma.
- All declarations must be terminated by a semicolon (;).

Two kinds of variables
- Local Variables - Variables that are declared inside a function are called local variables. It can only be referenced by statements that are inside the block in which the variables are declared.

- Global Variables - Global variables are known throughout the entire program and may be used by any piece of code. Global variables are created by declaring them outside of any function.


- Constants are identifier / variables that can store a value that cannot be changed during program execution.
- Example: const int count = 100;
- Where integer count has a fixed value of 100.

Arithmetic, Logical, Relational, and Bitwise Operations
- Operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
- There are three classes of operators in C: arithmetic, logical and relational, and bitwise.

Arithmetic Operators
Operator Action
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus Divisor
-- Decrement a value
++ Increment a value

Relational and Logical Operators
- In the term relational operator, the word relational refers to the relationship values can have with one another.
- In the term logical operator, the word logical refers to the ways these relationships can be connected together using the rules of formal logic.

Relational Operators

Operators Action
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
== equal
!= Not equal

Logical Operators

Operators Action Truth Table
&& AND true && true = true
true && false = false
false && true = false
false && false = false

OR true true = true
true false = true
false true = true
false false = false

! NOT !true = false
!false = true

Bitwise Operator
- Bitwise operators are the testing, setting or shifting of the actual bits in a byte or a word, which corresponds to C’s standard char and int data types and variants.
- Bitwise operators cannot by used on type float, double, long double, void or other more complex types.

The ? Operator
? Operator is a very powerful and convenient operator that can be used to replace certain statements of the if-then-else form.
- Example: y= x > 9 ? 100: 200
is equivalent to
If (x>9)
y=100;
Else
Y=200;

Evaluation of Expression
- Expression refers to anything that evaluates to a numeric value.

Order of Precedence
- Order of Precedence
()
!, unary +, -
*. /. %
binary + , -
<, <=, >, >=
==, !=
&&


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 in calling IBM-PC ROM BIOS.
- ctype.h – contains information used by the calssification 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

Monday, September 15, 2008

LEARNINGS OF THE WEEK
by: Mary Trishia V. Tabigue IV- RIZAL


I also learn about using the Turbo TC.

Structure of a simple C program

#include#define directivemain(){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.nalloc.h – declares memory management functions.nconio.h – declares various functions used in calling IBM-PC ROM BIOS.nctype.h – contains information used by the calssification and character convertion macros.nmath.h – declares prototype for the math functions.nstdio.h – defines types and macros needed for standard I/O.nstring.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

n& - address of operator* - indirection operator / pointer

Saturday, September 13, 2008

LEARNINGS OF THE WEEK (TAGARO)

LEARNINGS OF THE WEEK
By: Sharra Mae S. Tagaro IV- Rizal
DATA TYPES
DATA TYPES AND KEYWORDS
There are five elementary data types in C: character (char), integer (int), floating point, double floating point and void.
  1. CHAR
    -Values of type char are used to hold ASCII characters or any 8-bit quantity. Bidwidth-8; range- 0 to 255
  2. INT
    -Variables of type int are used to hold real numbers. Real numbers have both an integer. Bidwidth- 16; range- 32768 to 32767
  3. Float and Double
    -Values of type float and double are used to hold real numbers.
    -Real numbers have both an integer and fractional component. Float: Bidwidth- 32; range- 3.4 X 10-38 to 3.4 X 1038 Double: Bidwidth- 64; range- 1.7 x 10-308 to 1.7 x 10308
  4. Void
    -The type void has three uses:
    -To declare explicitly a function as returning no value.
    -To declare explicitly a function as having no parameters.
    -To create generic pointers. Bidwidth- 0; range- valueless

Type Modifiers

-Except type void, the basic data types may have various modifiers preceding them. A modifier is used to alter the meaning of the base type to fit the needs of various situations more precisely.
The list of modifiers includes the following:
-Signed
-Unsigned
-Long
-Short

Keywords
-Keywords in C are reserved words that have a special meaning.
-Reserved words are words "reserved" by the programming language for expressing various statements and constructs, thus, these may not be redefined by the programmer.

Friday, September 12, 2008

Learnigns of the Week (ROLLORATA)

DATA TYPES

DATA TYPES AND KEYWORDS

l There are five elementary data types in C: character (char), integer (int), floating point, double floating point and void.

CHAR
l Values of type char are used to hold ASCII characters or any 8-bit quantity.

INT
l Variables of type int are used to hold real numbers. Real numbers have both an integer.

Float and Double
l Values of type float and double are used to hold real numbers.
l Rea numbers have both an integer and fractional component.

Void
l The type void has three uses:
– To declare explicitly a function as returning no value.
– To declare explicitly a function as having no parameters.
– To create generic pointers.

Type Bidwidth Range

char 8 0 to 255
int 16 -32768 to 32767
float 32 3.4 X 10-38 to 3.4 X 1038
double 64 1.7 x 10-308 to 1.7 x 10308
void 0 valueless


Type Modifiers
l Except type void, the basic data types may have various modifiers preceding them.
l A modifier is used to alter the meaning of the base type to fit the needs of various situations more precisely.

Type Modifiers
l The list of modifiers includes the following:
– Signed
– Unsigned
– Long
– Short

Keywords
l Keywords in C are reserved words that have a special meaning.
l Reserved words are words “reserved” by the programming language for expressing various statements and constructs, thus, these may not be redefined by the programmer.

Keywords
l List of 32 Keywords / Reserved words as defined by the ANSI standard.
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while

Thursday, September 11, 2008

LEARNINGS OF THE WEEK
by: Mary Trishia V. Tabigue IV- RIZAL
THE C PROGRAMMING LANGUAGE


Four parts of C environment

1.) Main menu
2.) Editor status line and edit window
3.) Compiler message window

4.) “Hot Keys” quick reference line

1.) Main menu
Instructs C to do something as indicated in the list of menu. It can be activated or can be used by pressing Alt key and the first letter of the menu. For example, press Alt+F to activate File menu. The basic menu of C consist of file, run, compile.

2.) Editor status line and edit window
It is where you type your program and where you see the current line and column of the text you typed. If you try to press Alt- I or Insert Key, the word insert disappears, meaning that the window is in overwrite mode. Press again “insert” to return to the normal mode and notice that the word insert appears again.

3.) Compiler Message Window
oThe message window is located beneath the middle of edit window and Hotkeys.oIt is used to display various compiler or linker messages.

4.) “Hot Keys” quick reference line
Hot Keys is located at the bottom of C operating screen. It refers to shortcut or shorthand for selecting a menu. Two sets of Hot keys are available: the normal ones and the alternate set. Press the indicated key to use normal hotkeys. For example, press F1 to activate help. On the other hand, press Alt key briefly and the corresponding Function key to use alternate hot keys.

DATA TYPES AND KEYWORDS
lThere are five elementary data types in C: character (char), integer (int), floating point, double floating point and void.

CHAR
lValues of type char are used to hold ASCII characters or any 8-bit quantity.INT
Variables of type int are used to hold real numbers. Real numbers have both an integer


Float and Double
lValues of type float and double are used to hold real numbers.lRea numbers have both an integer and fractional component

Void
The type void has three uses:–To declare explicitly a function as returning no value.
–To declare explicitly a function as having no parameters.
–To create generic pointers

Type Modifiers
lExcept type void, the basic data types may have various modifiers preceding them.lA modifier is used to alter the meaning of the base type to fit the needs of various situations more precisely.

Keywords
lKeywords in C are reserved words that have a special meaning.lReserved words are words “reserved” by the programming language for expressing various statements and constructs, thus, these may not be redefined by the programmer.

Saturday, September 6, 2008

LEARNINGS OF THE WEEK (TAGARO)

LEARNINGS OF THE WEEK
By: Sharra Mae S. Tagaro IV- Rizal
Four parts of C environment
  • Main menu
  • Editor status line and edit window
  • Compiler message window
  • “Hot Keys” quick reference line

Main menu

  • Instructs C to do something as indicated in the list of menu.
  • It can be activated or can be used by pressing Alt key and the first letter of the menu.
  • For example, press Alt+F to activate File menu.

Basic menu of C

  • File – used to load and save files, handles directories, invokes DOS and exits C.
  • Run – used to compile (checks for errors), links and runs the program currently loaded in the environment.
  • Compile – used to compile the program currently in the environment.

Submenu under file menu

  • Load – enables the user to select a file to be opened or loaded into the editor.
  • Pick – enables the user to select a file based on the last nine files previously opened or edited.
  • New – lets the user edit a new file or start new programs.
  • Save – store or saves the file currently in the editor.
  • Write to – enables the user to save a file using a different filename.
  • Directory – displays the content of the current working directory.
  • Change dir – enables the user to specify the defined path to change the default path or directory.
  • OS shell – loads the DOS command processor and lets the user execute DOS commands.
  • Quit – lets the user to exit or quit C.

Editor Status Line and Edit Window

  • It is where you type your program and where you see the current line and column of the text you typed.
  • If you try to press Alt- I or Insert Key, the word insert disappears, meaning that the window is in overwrite mode. Press again "insert" to return to the normal mode and notice that the word insert appears again.

Message Window

  • The message window is located beneath the middle of edit window and Hotkeys.
  • It is used to display various compiler or linker messages.

Hot Keys

  • Hot Keys is located at the bottom of C operating screen.
  • It refers to shortcut or shorthand for selecting a menu.
  • Two sets of Hot keys are available: the normal ones and the alternate set.
  • Press the indicated key to use normal hotkeys. For example, press F1 to activate help. On the other hand, press Alt key briefly and the corresponding Function key to use alternate hot keys.