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
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
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
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
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