Oct 28

Definition of Repetition

Repetition means One or more instruction repeated for certain amount of time. Number of repetition can be predefined (hard-coded in program) or defined later at run time

There are 3 sets of repetition in programming : For, While, & Do While.

Repetition using For

There are two types of loops for… well… For

Infinite Loop

Loop with no stop condition can use “for-loop” by removing all parameters (exp1, exp2, exp3). To end the loop use break.

Nested Loop

Loop in a loop. The repetition operation will start from the inner side loop.

Repetition using While

The repetition statement provides the ability to execute a statement sequence repeatedly, either for a counted number of times (using the for…to clauses) or until a condition is satisfied (using the while clause). Both forms of clauses can be present simultaneously.

In while operation, statement block of statements may never be executed at all if exp value is false

Repetition using Do-While

In do-while on the other hand statement block of statements will be executed min once. It’s basically while with some modifications.

Oct 21

Today we’re gonna talk about Selections in Algorithms & Programmings

 

Selection Definition

in an algorithm implementation, an instruction or block of instructions may be executed (or not) with certain predetermined condition

Syntax:

–if

–if-else

–switch-case

IF

Syntax :

if (boolean expression) statement;

or

if (boolean expression) {

     statement1;

     statement2;

  ……

}

If boolean expression resulting in True, then a statement or some statements will be executed.

Selection: IF-ELSE

Syntax :

if (boolean expression) statement1;

else statement2;

or

if (boolean expression){

   statement1;

   statement2;

   ……

}

else {

   statement3;

   statement4;

   …

}

If boolean expression resulting in TRUE, then statement1 or  block statement1 will be executed, if FALSE then statement2 or block statement2 be executed.

NESTED-IF

  • Nested selection occurs when the word IF appears more than once within IF statement.

Syntax :

if (boolean expression) statement1;

if (boolean expression) statement2;

if (boolean expression) statement3;

or

if (boolean expression) statement1;

else

  if (boolean expression) statement2;

  else

  if (boolean expression) statement3;

SWITCH-CASE

Switch-Case Operation

This statement is used in exchange of IF-ELSE, when if-else nested number of level is enormous and difficult to read

Syntax:

switch (expression) {

  case constant1 : statements1; break;

  .

  .

  case constant2 : statements2; break;

  default : statements;

}

?: Operator

The operator ? : is similar to the IF statement, but it returns a value

Syntax:

  condition ? then-expression : else-expression

Using this operator, you can rewrite

if(a > b)

max_value = a;

else

max_value = b;

as

max_value = (a > b) ? a : b;

Oct 14

Today. we’ll talk about Operator, Operand and Arithmetic

  • Operator is a symbol to process values in result for a new value
  • Operand is part which specifies what data is to be manipulated or operated on
  • Example :

  C = A + B 

  (= and + sign are operators, A, B and C are operands)

  • Based on its operand number, operator can be divided into three:

–Unary operator  (needs one operand)

Binary operator  (needs two operands)

Ternary operator  (needs three operands)

Based on its operation type, operator can be grouped as:

–Assignment Operator

–Logical Operator

–Arithmetic Operator

–Relational Operator

–Bitwise Operator

–Pointer Operator

Assignment Operators

A binary operator

Used in assigning value to an operand

 

Left hand side operand (Operand1) should have (L-Value) such as variable

Right hand side operand (Operand2) can be constant, another variable, expression or function

Arithmetic Operators

Modulo

–Symbol : %

–Binary operator

–To find reminder of a division

–N % 2, can be used to find an odd or even number

  • N % 2 = 0 ® N is even
  • N % 2 = 1 ® N is odd
  • Increment and Decrement

–Symbol : ++(increment), –(decrement)

–Unary operator

–Increase (++) and decrease (–) the value of a variable by 1.

–Its position can be in the front (pre) or after (post) a variable.

Relational Operators

Use to compare to values with TRUE or FALSE result

FALSE in C language equals to the value of zero

TRUE on the other hand not equal to zero

TRUE set by a C program at run time equal to the value of one

 

Oct 7

Alright, so here I am today writing a few summaries about algorithms and programming.

Here we go.

Algorithms can be interpreted as a set of logical sets to solve a problem to produce of solution

Programming is a set of instructions that is put into the computer so that the computer can work according to the instructions.

So, Inside of algorithms and programming, there’s a… thing… called OOP or Object Oriented Programming. Now inside of OOP there are 5 more things, Encapsulation, Inheritance, Abstraction, Polymorphism, and Interface

In algorithms and programming there are compilers, assembler, and interpreter.

Compiler compiles source code to files that can be executed

Interpreter is computer program that executes programming instructions

Assembler is a program that translates assembly language to machine code.

here are some programming language from ranging from easy to hard

Assembler : Easy

C, Pascal, and Fortran = Medium

Java, C++, C# = Hard

Now, people have recommended us to use C as a programming language. Why use C? Because the C language are Flexible, Portable, Well Known, and Supported by a large number of libraries.

People also recommends us to use Flowcharts rather than a long writing. Why do people use flowchart so much and not writings? It’s because PICTURES ARE EASIER TO UNDERSTAND THAN FULL WORDS.

In algorithms and programming there are also pseudocode and Source code

Pseudocode are an artificial & informal language and helps develop algorithms

Source code are a collection of computer instructions written using some human-readable computer language, usually as text.

There is also a structure theorem, Structure theorem makes computer programming possible using three control structures : Sequence, Selection, and Repetition

Sequence are a series of consecutive commands / statements

Selection are number of statements / commands that allows a program to choose different actions, thus the selection that the program selects will run

Repetition are number of statements / commands that allows a program to repeat said actions

Well, that’s all that I’ve summarized about algorithms and programming, this is Blackcat signing off!