Anda di halaman 1dari 7

Objectives

 Upon completion of this lesson, students will be able to:

Convert algorithm for programming application by applying three


phases in software development process

Distinguish variables and reserve words

NCB20103
COMPUTER PROGRAMMING FOR ENGINEERS
Use different types of operators in programming implementation

1. INTRODUCTION TO C PROGRAMMING
Differentiate between statements and expressions

Topics Topics
1. Problem solution and software development 1. Problem solution and software development
2. Algorithm 2. Algorithm
3. Variables and assignment statements 3. Variables and assignment statements
4. Statements and expression 4. Statements and expression

3 4
1. Problem solution and software 1. Problem solution and software
development development
Problem solution (problem solving)  Software development 3 phases
Problem-solving consists of using generic or ad hoc i. Development and design
methods, in an orderly manner, for finding solutions to any Analyze the problem
 Input, output, formula
given problems.
Develop solution (Algorithm)
 Pseudocode, flowchart
Code the solution (coding)
Software development  Syntax error, logic error, run-time error
Test and correct the program
A process in the development of software product
ii. Documentation
iii. Maintenance

5 6

1. Problem solution and software 1. Problem solution and software


development development

Programming process Programming shortcut?

7 8
1. Problem solution and software
development Topics
Example: 1. Problem solution and software development
Create a program to calculate and print out the total
numbers of two integers.
2. Algorithm
3. Variables and assignment statements
Solution: 4. Statements and expression
Analyze the problem
 Input: two integer (num1 and num2)
 Output: total of two integers (total)
 Formula: total = num1 + num2

9 10

2. Algorithm 2. Algorithm
 Algorithms as path through Problem spaces Algorithm
a precise specification of a behavior
Step-by-step sequence of instruction that described
Algorithm: how data is to be processed to produced desired
intended to solve a well-defined problem
outputs

Coding: the translation of an algorithm into a


particular programming language
How to describe algorithm?
By two ways:
Program: a step-by-step execution plan that a
computer can perform as a sequence of 1. Pseudocode
simple steps or instructions 2. Flowchart
11 12
2. Algorithm 2. Algorithm
2.1 Pseudocode 2.2 Flowchart
To describe algorithms in a English-like phrases that A flowchart is a diagram that depicts the flow of a
used to write computer programs program

Example: Area of a circle Uses simple geometric symbols and arrows to define
Write a pseudocode to find relationships
the area of a circle using Pseudocode
the following formula: Input the value of radius
Area = pi x radius2
Set value of PI.
Prompts the user to enter
a value for radius and Calculate area = pi x radius2
reads it. Display the result Print area
on the screen.
13 14

2. Algorithm
2.2 Flowchart Topics
1. Problem solution and software development
2. Algorithm
3. Variables and assignment statements
 Common flowchart symbol: 4. Statements and expression

15 16
3. Variables and assignment statements 3. Variables and assignment statements
3.1 Operators 3.1 Operators
 Operator - A symbol that represents a specific action  Logical operators:
 Assignment operator: = i. ! Logical negation
 Arithmetic operators: ii. && Logical AND
i. + Addition iii. || Logical OR
ii. - Subtraction
iii. * Multiplication
iv. / Division
 Increment operator: ++
v. % Modulus  Add 1 to its operand
 Relational operators:
i. < Less than comparison  Decrement operator: --
ii. <= Less or equal comparison  Subtract 1 from its operand
iii. == Equal comparison
iv. > Greater than comparison
v. >= Greater or equal comparison
vi. != Not equal comparison

17 18

3. Variables and assignment statements 3. Variables and assignment statements


3.2 variables 3.2 variables
A variable is a location in memory that can be referred Variable names in C
to by an identifier and in which a data value that can be  May only consist of letters, digits, and underscores
changed is stored
 May be as long as you like, but only the first 31
characters are significant
A value that can be changed, depending on conditions  May not begin with a number
or on information passed to the program  Case sensitive: A a
 May not be a C reserved word (keyword)

19 20
3. Variables and assignment statements 3. Variables and assignment statements
3.2 variables 3.2 variables
Reserved words in c Naming convention
C programmers generally agree on the following
auto break int long conventions for naming variables.
case char register return  Begin variable names with lowercase letters
const continue short signed  Use meaningful identifiers
default do sizeof static  Separate words within identifiers with underscores or mixed
upper and lower case.
double else struct switch  Examples: surfaceArea surface_Area surface_area
enum extern typedef union  Be consistent!
float for unsigned void
goto if volatile while
21 22

Topics 4. Statements and expression


1. Problem solution and software development Statements
2. Algorithm A statement is a block of code that does something.

3. Variables and assignment statements


Example:
4. Statements and expression o An assignment statement assigns a value to a variable.
o A for statement performs a loop

23 24
4. Statements and expression
Expression
Any legal combination of symbols that represents a value.

Example:
o X > 10
o Y+5

25 26

Anda mungkin juga menyukai