Itec 102 Reviewer

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

ALGORITHMS and FLOWCHART

WHAT IS AN ALGORITHM?

An Algorithm is a set of instructions for solving problem, step-by-step. Typically, algorithm are
executed by computers and should contain an INPUT, PROCESS and an OUTPUT.

An Algorithm is a “finite set of precise instructions for performing a computation or for solving a
problem”

Examples:
A program is one type of algorithm
A direction to somebody’s house is an algorithm
A recipe for cooking a cake is an algorithm
The steps to compute the cosine of 90 degree is an algorithm

Algorithms generally share a set of properties


1. Input
2. Output
3. Definiteness
4. Correctness
5. Finiteness
6. Effectiveness
7. Efficiency
8. Generality

VARIABLES
 MATHEMATICS- A Letter than can represent any number
A=4+b
 PROGRAMMING- A Letter / Word that serves as a temporary storage that can
represent any value

Programming Problem

Create a Program that will display the sum of 2 number inputted by the user.

Algorithm:

1. Declare 3 Variables,
2 Addends
1 for the Sum
2. Let the user input the addends
3. Perform the addition between the addends and assign it to the sum
4. Display the sum
FLOWCHART
WHAT IS A FLOWCHART?
A method that allows a programmer to represent the Algorithm in a diagram or an
illustration.

Flowcharts represents the sequence of a programming algorithm by using standard graphic


symbols that will represent the Input, Process and the Output.

Flowchart vs Pseudocode
 Flowchart- Graphically depicts the logical steps to carry out a task and shows how the
steps relate to each other.

 Pseudocode- Uses English-like phrases with some Visual Basic terms to outline the
program.
PSEUDOCODE

USES OF PSEUDOCODE
1. To help non-programmers understand what is happening or what is the process of the
program.

2. Solving logic error and debug computer program for the programmers.
DATA TYPES, VARIABLES AND CONSTANT
Data types, Variables and Constant
C# is a strongly typed language. It means, that you cannot use variable without data
types. Data types tell the compiler that which type of data is used for processing. Such as if
you want to work with string value then you will have to assign string type variable to work
with. C# provides two types of data types: Value types and Reference types.

A Value type data type stores copy of the value whereas the Reference type data
types stores the address of the value. C# provides great range of predefined data types but it
also gives the way to create user defined data types.

WHAT IS VARIABLE?
A variable refers to the memory address. When you create variable, it creates holds
space in the memory that is used for storing temporary data. As you know about c# data
types, each data type has predefined size.

ATTRIBUTES OF A VARIABLE
A variable has;
 Name
 Address
 Datatype
 Value

RULES IN NAMING VARIABLES


1. It must begin with a letter
2. It should not contain any spaces
3. It should not be a keyword
4. Make it descriptive

DECLARING VARIABLE
<datatype> varname = value;

string firstName;
string lastName=”Origines”;
int num = 0, num2=0;

Conversion
C# accepts string value by default. If you are using other value then you will have to convert
of specific data types.

num1 = Convert.ToInt32(Console.ReadLine());
C# OPERATORS
C# PROGRAMMING OPERATORS
Operators are used for building expressions in C#. To calculate the value of a
variable or performs the operation in the variable you will have to make a proper expression.
These expressions are made using C# operators.

C# provides wide range of operators as arithmetic operators, assignment


operators, unary operators, comparison operators, logical operators.

ARITHMETIC OPERATOR
Operators are a very useful thing in computing value. While writing a program, you
need various types of operators to calculate the value. These operators are categorized as
different categories in C sharp tutorial that performs specific task ex. The C# arithmetic
operator performs the basic calculation as add, subtraction, multiplication, division, and
modulus whereas other operators perform a different kind of task.

Arithmetic Operators are used for basic mathematical calculation in C# programming.


The list of Arithmetic Operators is given below:
ASSIGNMENT OPERATOR
The C# assignment operator is generally suffix with arithmetic operators. The symbol
of c sharp assignment operator is “ = " without quotes. The assignment operator is widely
used with C# programming.

Consider a simple example:


result=num1+num2;

In this example, the equal to (=) assignment operator assigns the value of num1 +
num2 into result variable.

UNARY OPERATOR
The C# unary operator is widely used for increment or decrement value by 1. This
operator is widely used with loop constructs to increment loop by 1. It is very easy to use and
understand C# unary operators.

UNARY OPERATOR
++ INCREMENT OPERATOR:
This operator is pronounced as increment operator. It is used for incrementing value
by 1. It is used in C# programming by two types: Pre-increment (++i) and Post-increment (i+
+). In pre-increment, first it increments by 1 then loop executes whereas in Post-increment,
the loop executes then it increments by 1.

-- DECREMENT OPERATOR:
The behavior of decrement operator is just opposite from increment operator. It is
used for decrementing the value by one. It has also two types: Pre-Decrement (--i) and Post
Decrement (i--). In pre-decrement the value is decremented by one then loop executes
whereas in post-decrement the loop executed then the value decrements by one.

COMPARISON OPERATOR
The C# comparison operator is used to compare two operands. It returns true or false
based on the comparison.

Consider x is a variable and the value assigned the x=2 then,

LOGICAL OPERATOR
The C# Logical Operator also evaluates the values and returns true or false as output.
Based on true-false the program behaves dynamically at runtime. This operator is widely used
with C# programming.

LOGICAL OPERATOR
“And” Logical Operator (&&)

&& Operator is pronounced as “and” operator. It returns true if both or all the
conditions are true and return false if any of the condition is false.

“Or” Logical Operator (||)

|| Operator is pronounced as “or” operator. It also returns true or false based on


condition. If any one of the condition matches then it returns true but if both or all the
conditions are false then it returns false.

“Not” Logical Operator (!)


! Operator is pronounced as “not” operator. It returns true if expression is false.

“XOR” Logical Operator (^)

^ Operator: It is pronounced as “xor” operator. It returns false if the following


condition matches:

(i) if both or all the expression returns true.


(ii) If both or all the expression returns false.

You might also like