Saturday, September 27, 2008

Learnings of the Week - September 27, 2008

VARIABLES, CONSTANTS, OPERATORS AND EXPRESSION

IDENTIFIERS DEFINED
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 DEFINED
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.
It should not begin with a digit.
An identifier defined in the C standard library should not be redefined.
It is case sensitive; meaning uppercase is not equal to the lowercase.
Do not include embedded blanks.
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
Type variable list;
Example: int, i, j, k;
Short i,j,k;
Note that 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 (;).


The two kinds of variables are the local variables and global 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 DEFINED
Constants are identifier/variables that can store a value that cannot be changed during program execution.


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.
The arithmetic operators are:


Operator

+
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.
The relational operators are:

Operators


>
Greater than


>=
Greater than or equal to


<
Less than


<=
Less than or equal to


==
Equal


!=
Not equal


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.


EVALUATION EXPRESSION
Expression refers to anything that evaluates to a numeric value.


ORDER OF PREFEDENCE

Order of Precedence


( )
!, unary +,-
* . /. %
Binary + , -
<, <=, >, >=
==, !=
&&



Posted by:
RAE ANGELINE S. PALEN

Friday, September 26, 2008

LEARNINGS OF THE WEEK (sept. 22-26)

LEARNINGS OF THE WEEK (Sept. 22-26)
By: Hanna Deborrah T. Ongking

This week, I have learned about the conditional statements which we applied in our activities in computer programming.

Below, are the lessons we've discussed this week.

Conditional Statement

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

The If Statement

The If-Else Statement

The Nested-If Statement

The If-Else-If Ladder

The Switch Statement

The Nested Switch Statement

The If Statement

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.

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.

Note: Only the code associated with the if or the code that is associated with the else executes, never both.

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.

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

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

Fortunately, 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.

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.

l 1. if…..

l 2. if ……

l 3. else

l Consider the following situations:

Situations 2. The else in number 5 is paired with the if in number 1.

l 1. if ….

l 2. {

l 3. if ….

l 4. }

l 5. else

Note that there is a pair of braces found in number 2 and number 4.

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.

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.

This makes the if statement in number 1 the nearest if statement to the else statement in number 5.

The if-else-if Ladder

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

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.

In an if-else-if ladder statement, 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: 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

The switch statement is a multiple-branch decision statement.

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;

}

In a switch 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 (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 that point of execution, you should jump to the end of the switch statement by the symbol }.

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;

}

Thursday, September 25, 2008

^^Learnings of the Week

Submitted by:

Joyce Niko D. Perez

IV-RIZAL


VARIABLES, CONSTANTS, OPERATORS AND EXPRESSION

Identifiers Defined

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 Defined

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

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

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.

Constant Defined

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 Operators

Operator Action

+ Addition

- Subtraction

* Multiplication

/ Division

% Modulus Divisor

-- Decrement a value

++ Increment a value

Relational Operators

n Operators Action

> Greater than

>= Greater than or equal to

< Less than

<= Less than or equal to

== equal

!= Not equal

Logical Operators

n 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

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

Saturday, September 20, 2008

Learnings of the Week - September 20, 2008

DATA TYPES

DATA TYPES AND KEYWORDS

There are Five Elementary Data Types in c:

CHAR
Values 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
Values of type float and double are used to hold real numbers. Real 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, and, to create generic pointers.

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. The 32 keywords/reserved words defined by the ANSI standard are the following:

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

Posted by:
RAE ANGELINE S. PALEN

Wednesday, September 17, 2008

^^Learnings of the Week

Submitted by:
Joyce Niko D. Perez
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.

CHAR

Values 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

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

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

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:

l Signed

l Unsigned

l Long

l 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

learnings of the week-hanna

In this week, we tackled about the overview of the C Programming Language, the Flowcharting and the 3 Basic Control Structures.
HISTORY
B was developed in the year 1970 by Ken Thompson. It was the successor of the Basic Command Programming Language (BCPL) which was developed by Martin Richards.
Dennis Ritchie invented and first implemented the C programming language In Bell Laboratory.
C was originally developed under UNIX environment running in DEC PDP-11.
C stands for Combined Programming Language and sometimes called as System Programming Language (SPL)
Brian Kernighan and Dennis Ritchie created the famous book "The C Programming Language"
X3J11 committee was created in the year 1983 under the American National Standard Institute (ANSI).
ANSI cooperated with the International Standard Organization (ISO) to refer as ANSI/ISO 9899:1990
C is often called as a middle-level language. As a middle-level language, it combines elements of high-level language with the functionalism of assembly language.
They have only 32 keywords (27 from Kernighan and Ritchie and 5 from ANSI Standardization Committee.
C is mainly used because it produces codes that run as fast as codes written in assembly language.Some Examples
Uses of C Operating system
Language compilers
Assemblers
Text editors
Print spoolers
Network devices
Modern Programs
Databases
Language interpreters
Utilities
FEATURES OF C LANGUAGES
It is a simple core language.
It focuses on procedural programming paradigm.
Parameters are passed by values, never by references.
It encourages in the creation of libraries user-defined functions.
It is flexible.
FLOWCHARTING
use of symbols, phrases to designate the logic steps of how the problem is solved.
a common method for defining the logical steps of flow within a program by using a series of symbols to identify the basic input, process and output function within a program.
a diagram representing the logical sequence in which a combination of steps is to be performed.
It is a blueprint of the program.ALGORITHM
It is a finite set of instructions that specify a sequence of operations to be carried out in order to solve a specific problem or class of problems.3 BASIC CONTROL STRUCTURES
Sequence - a process executed from one to another in a straightforward manner.
Selection - a choice is provided between alternatives.
Repetition (Looping) - this structure provides for the repetitive execution of an operation or routine while the condition is true. The condition is evaluated before executing any process statement.
COMMONLY USED OPERATORS IN FLOWCHARTING
Arithmetic Operators+ addition- subtraction* multiplication/ divisionLogical Operators&& AND OR! NOT