Fundamentals of
Computer Programming 1
Johaira U. Lidasan, MCS
Introduction to Computers
1. Mainframes/Supercomputers
2. Personal Computer
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Computer Hardware
1. Main Memory
2. Secondary Memory
3. Central Processing Unit
4. Input Devices
5. Output Devices
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Computer Software
1. Operating System
2. Application Software
3. Computer Languages
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Types of Programming Languages
1. Machine Language – a collection of very
detailed, cryptic instructions that control the
computer’s internal circuitry. Natural dialect
of the computer
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Types of Programming Languages
2. High Level Language
General-purpose language
Special-purpose language
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
What is Algorithms?
- Used in computer science to describe a
problem-solving method suitable for
implementation as computer programs
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
C Language Elements
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
A Model for Creating Computer Software
- Specify the problem
- Develop a design (algorithm)
- Implement the design
- Maintain the design
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Steps needed to solve a problem:
- Specific
- Unambiguous
- Language independent
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Ambiguous Instructions:
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Ambiguous Instructions:
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Ambiguous Instructions:
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Ambiguous Instructions:
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Ambiguous Instructions:
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Techniques for Laying out an Algorithm
- Pseudo-code
- Flowcharts
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Pseudo-Code
- Is an artificial and informal language that
helps programmers develop algorithms
- Employs “programming-like” statements to
depict the algorithm
- No standard format (language independent)
and can be informal English, combinations of
computer languages and spoken language.
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Pseudo-Code Statements
Output
Input
Process
Decision
Repetition
Statements are carried out in order
Example: calling up a friend
1. Look up telephone number
2. Enter telephone number
3. Wait for someone to answer
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Pseudo-Code Example
Example:
Write an algorithm that converts miles to
kilometers. Remember that 1 mi = 1.609 km.
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Pseudo-Code Example
• Get the distance in miles
• Convert the distance to kilometers. Use the
formula kilometers = distance * 1.609
• Display the distance in kilometers
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Pseudo-Code Example
Example:
Write an algorithm to determine a student’s final
grade and indicate whether it is passing or
failing. The final grade is calculated as the
average of four marks.
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Pseudo-Code Example
• Input a set of 4 marks
• Calculate their average by summing and
dividing by 4
• If average is below 75
Print “Fail”
else
Print “Pass”
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Pseudo-Code Exercise
1. Write a pseudocode that asks the user to enter
the radius of a circle and then computers and
displays the circle’s area. Use the formula
Area = PI x Radius x Radius
Where PI is the constant macro 3.14159
2. Write a pseudocode that asks for a number
from the user and display if the number is even
or odd
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Write a pseudocode that determine the
temperature of the room. If it is 13 degree,
then adjust the temperature to 24 degree, else
maintain the 20 degree temperature.
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Algorithm and Pseudocode
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Symbols:
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Symbols:
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Symbols:
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Flowchart
- Is a diagrammatic representation of an
algorithm
- It uses different symbols to represent the
sequence of operations, required to solve a
problem
- It serves as a blueprint or a logical diagram of
the solution to a problem
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Basic Flowchart Symbol
Represents start and stop/begin and end
Represents declaration
Represents input and output
Represents process or calculation
Represents predefined
Represents condition process/module
Represents control flow
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Flowchart Example
Write an algorithm that will get a number from
the user and display it. Begin
1. Declare variable n as an
integer Int n
2. Get a number from the
user and assign it to n
3. Display n Get n
Display n
End
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Flowchart Example
Write an algorithm that will calculate the area of
a circle. Begin
Float radius,
1. Declare variable radius as area
float
2. Get radius Get radius
3. Calculate area using this
formula area = PI * (radius
* radius) area = PI * (radius * radius)
4. Display area
Display area
End
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Comments
- Are an integral part of program code in any
programming language
- /*…*/
- //
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Keywords
- There are 32 keywords defined as keywords
that have predefined uses and cannot be
used for any other purpose in a C program
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Escape Sequences
- Are specially sequenced characters used to
format output
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Primary Data Types
- Integers
- Floating-point numbers
- Characters
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Arithmetic in C
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Order of Precedence
Computer Programming 1 JOHAIRA U. LIDASAN, MCS
Exercises:
1. Given a = 5, b = 1, x = 10 and y = 5, create a
program that outputs the result of the
formula f = (a – b)(x – y) using a single
printf() function
2. Create a new program that prompts a user
for numbers and determines total revenue
using the following formula: Total Revenue
= Price * Quantity
Computer Programming 1 JOHAIRA U. LIDASAN, MCS