CC102 UNIT A Introduction To Programming and C-3
CC102 UNIT A Introduction To Programming and C-3
INTRODUCTION TO
PROGRAMMING
AND CC102 - Computer Programming 1
01
Analyze fundamental
programming concepts and
apply them to construct basic C
programs.
02
Synthesize knowledge of C syntax
and structure to effectively
represent program solutions in
code.
TABLE OF CONTENT
INTRODUCTION TO C
02 • Structure
• Compilation Structure
CORE SYNTAX
03 • Data Types
• Variables
• Operators
• Input/ Output
BASIC
PROGRAMMING
CONCEPTS
• Algorithms
• Flowchart
• Pseudocode
• COMPUTER PROGRAMS - These are the collections of instructions that tell a computer what
to do, how to interact with the user, interact with the computer hardware and process data.
• The first programmable computers required the programmers to write explicit instructions to
directly manipulate the hardware of the computer.
• Computer programs, known as software. You tell computer what to do through programs.
• Computers do not understand human languages, so you need to use computer languages to
communicate with them.
■ Machine Languages
■ Assembly Languages
■ High-Level Languages
• MACHINE LANGUAGE - It is also known as Low-Level Language and is the only language that
can be understood by the computer.
• The machine language contains only two symbols 1 & 0. All the instructions of machine
language are written in the form of binary numbers 1s & 0s.
• ASSEMBLY LANGUAGE - It is also known as Mid-Level Language in which the instructions are
created using symbols such as letters, digits and special characters.
• In assembly language, we use predefined words called mnemonics. Binary code instructions
in low-level language are replaced with mnemonics and operands in middle-level language.
• But the computer cannot understand mnemonics, so we use a translator called assembler to
translate mnemonics into machine language.
• ASSEMBLER - It is a translator which takes assembly code as input and produces machine
code as output.
• The high-level language is very similar to human languages and has set of grammar rules that
are used to make instructions more easily.
• Every high level language has a set of predefined words known as keywords and a set of rules
known as syntax to create instructions.
• The high-level language is easier to understand for the users but the computer can not
understand it.
PYTHON
VISUAL BASIC It is a general purpose programming
Basic-like visual language developed language that’s used to do things from
by Microsoft testing microchips at Intel, to building
video games.
C++ C
it is an extension of C programming It is designed to support only
language that supports object- procedure-oriented programming.
oriented programming and procedure Popular langage for developing system
oriented approach. General purpose applications such as operating system
and most popular. and compilers.
1 2 3 4
ALGORITHM DESIGN
PROBLEM PROBLEM CODING AND
AND DATA
DEFINITION ANALYSIS DEBUGGING
REPRESENTATION
• Prior to creating the computer program, one must understand the problem clearly. The
statement of the problem must show the following:
• Based on the problem defined in the previous phase, analysis will take place. The statement of
the problem helps the programmer to understand:
PROBLEM 1
Create a program WHAT DETERMINE
WHAT DATA IS
SOLUTION/S THE POSSIBLE
that inputs three GIVEN?
CAN BE DONE? PRODUCT.
numbers from a
user and displays
their average. INPUT PROCESS OUTPUT
• Based on the problem defined in the previous phase, analysis will take place. The statement of
the problem helps the programmer to understand:
PROBLEM 1
Create a program
that inputs three
numbers from a
user and displays
their average. INPUT PROCESS OUTPUT
• Based on the problem defined in the previous phase, analysis will take place. The statement of
the problem helps the programmer to understand:
PROBLEM 1
Create a program WHAT DATA IS
that inputs three GIVEN?
numbers from a
user and displays
their average. INPUT PROCESS OUTPUT
• Based on the problem defined in the previous phase, analysis will take place. The statement of
the problem helps the programmer to understand:
PROBLEM 1
Create a program
THREE NUMBERS
that inputs three
numbers from a
user and displays
their average. INPUT PROCESS OUTPUT
• Based on the problem defined in the previous phase, analysis will take place. The statement of
the problem helps the programmer to understand:
PROBLEM 1
Create a program WHAT
THREE NUMBERS SOLUTION/S
that inputs three
CAN BE DONE?
numbers from a
user and displays
their average. INPUT PROCESS OUTPUT
• Based on the problem defined in the previous phase, analysis will take place. The statement of
the problem helps the programmer to understand:
• Based on the problem defined in the previous phase, analysis will take place. The statement of
the problem helps the programmer to understand:
• Based on the problem defined in the previous phase, analysis will take place. The statement of
the problem helps the programmer to understand:
PROBLEM 2
Compute and Print
out the Sum,
Average and the
Product of two
numbers. INPUT PROCESS OUTPUT
PROBLEM 2
Compute and Print
TWO NUMBERS
out the Sum,
Average and the
Product of two
numbers. INPUT PROCESS OUTPUT
PROBLEM 3
Write a program that
asks the user to enter
a number and
determines the result,
indicating whether
the number is
Positive, Negative, or
Zero.
INPUT PROCESS OUTPUT
PROBLEM 3
Write a program that
asks the user to enter
a number and A NUMBER
the number is
Positive, Negative, or
Zero.
INPUT PROCESS OUTPUT
• The analyzed problem from previous phase may be represented either of the following data
representation:
• CODING - It is the act of writing or creating the computer program or source code based on
the algorithm design and representation using the chosen programming language.
• Most of the time, after the computer programmer has written the source code, there are still
errors or bugs that needs fixing.
• DEBUGGING - This refers to the process of fixing bugs or errors in a computer program.
TYPES OF ERRORS
• It occurs during program execution • It is an error in the structure or spelling of • Unexpected/ unintentional errors resulted
• it is detected by a compiler a statement detected by a compiler from flaw in the program’s logic.
• It occurs because of logic error or during compilation of the program. • Produce undesired result or output,
memory leak • Cannot be detected by compiler
EXAMPLE: Missing semicolon, quote, etc. • Compare the result with manual process.
ASSIGNMENT NO. 01
1 WHOLE SHEET OF WHITE PAPER
1. Demonstrate the Problem Analysis phase for the problem below by identifying the input,
process, and output:
Write a program that asks the user to enter two numbers and determines the result,
indicating which number is larger between the two.
STEP 1 Start
STEP N Stop
STEP 1 Start
Create a program
STEP 4 Input third number
that inputs three
numbers from a STEP 5
Add the first number, the second number, and the third number, and assign the result to
sum using the formula: sum = first number + second number + third number
user and displays Divide the sum by 3 and assign the result to average using the formula:
STEP 6
their average. average = sum / 3
STEP 8 Stop
STEP 1 Start
Compute and Print Add the first number and the second number, and assign the result to sum using the
STEP 4
out the Sum, formula: sum = first number + second number
STEP 8 Stop
STEP 1 Start
PROBLEM 3
Write a program that STEP 2 Input number
asks the user to enter Determine the result of whether the number is positive, negative or zero by checking
a number and the following:
STEP 3 If number > 0, display the result as “positive”
determines the result, If number < 0, display the result as “negative”
indicating whether If number = 0, display the result as “zero”
the number is
STEP 4 Display result
Positive, Negative, or
Zero.
STEP 5 Stop
• Flowcharts help programmers and analysts understand, communicate, and analyze the logic
and flow of a program before actual coding begin.
TERMINAL PROCESSING
ON-PAGE OFF-PAGE
DECISION
CONNECTOR CONNECTOR
PREPARATION DATA
FLOWLINE
Presentation by Jerico D. Quinzon
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY (BSINFOTECH)
• TERMINAL SYMBOL – It indicated the beginning/ starting or ending/ stopping point of the
flowchart.
START BEGIN
STOP END
NOTE: You can only have one(1) begin/start and one(1) end/stop for your flowchart
• PREPARATION SYMBOL – It is used to initialize the value of the variables to be used in the
flowchart.
sum = 0 length = 0
age = 18 pi = 3.1416
• DATA SYMBOL – It is used for accepting data input or displaying the output.
INPUT INPUT
first number age
OUTPUT OUTPUT
sum area
NOTE: You should indicate whether the data symbol is used for INPUT and if it is used for
OUTPUT.
sum = n1 + n2 area = l * w
• DECISION SYMBOL – It is used for conditional statements when operation requires more than
one answer.
• There are two arrow heads going out from this symbol, either Yes/ True and No/ False.
T Y
grade >= 75 age != 18
F N
• ON-PAGE CONNECTOR SYMBOL – It is used to continue the flowchart within the same page.
A
PAGE 1
A
PAGE 1 PAGE 2
PROBLEM 1
Create a program that inputs three numbers from a user and displays their average.
ALGORITHM FLOWCHART
Add the first number, the second number, and the third number, and assign the result to sum
STEP 5 using the formula: sum = first number + second number + third number
Divide the sum by 3 and assign the result to average using the formula:
STEP 6 average = sum / 3
STEP 8 Stop
START
INPUT
first number
INPUT
second number
INPUT
third number
average = sum / 3
OUTPUT
average
STOP
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY (BSINFOTECH)
PROBLEM 2
Compute and Print out the Sum, Average and the Product of two numbers.
ALGORITHM FLOWCHART
Add the first number and the second number, and assign the result to sum using the formula:
STEP 4 sum = first number + second number
Divide the sum by 2 and assign the result to average using the formula:
STEP 5 average = sum / 2
Multiply the first number by the second number and assign the result to product using the
STEP 6 formula: product = first number * second number
STEP 8 Stop
START A
INPUT
average = sum / 2
first number
OUTPUT
sum = first number + second
sum, average,
number
product
A STOP
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY (BSINFOTECH)
PROBLEM 3
Write a program that asks the user to enter a number and determines the
result, indicating whether the number is Positive, Negative, or Zero.
ALGORITHM FLOWCHART
Determine the result of whether the number is positive, negative or zero by checking the
following:
STEP 3 If number > 0, display the result as “positive”
If number < 0, display the result as “negative”
If number = 0, display the result as “zero”
STEP 5 Stop
START A B
INPUT
number T OUTPUT
number
<0 “Negative”
number T OUTPUT
>0 “Positive” T
number OUTPUT
== 0 “Zero”
F
F
A B STOP
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY (BSINFOTECH)
• PSEUDOCODE – It is a way of planning out algorithms and programs using informal, human-
readable language that resembles programming logic. It is not meant to be executed by a
computer instead it serves as a bridge between the problem description and actual code.
• The first thing we do when designing a pseudocode is to decide on a name for the program.
• Let’s say we want to write a pseudocode to calculate interest, a good name for the
pseudocode would be CalculateInterest.
START CalculateInterest
• SEQUENCE – Instructions are designed to be executed in the order they are written. Ist is used
to show a single action, or one action followed in order sequentially by another. Actions can be
inputs, processes, of outputs.
START <ProgramName>
<Statement1>
<Statement2>
<Statement3>
<Statement4>
<Statement5>
<StatementN>
STOP
Presentation by Jerico D. Quinzon
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY (BSINFOTECH)
START OrderingPizza
Go to the phone
Dial the pizza place
Order the pizza
Hang up the phone
STOP
START <ProgramName>
IF (<condition>)
THEN <statement1>
ELSEIF (<condition>)
THEN <statement1>
ELSE <statement>
ENDIF
STOP
Presentation by Jerico D. Quinzon
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY (BSINFOTECH)
START OrderingPizza
IF (you have money)
THEN go to the phone
dial the pizza place
order the pizza
hang up the phone
ELSE do not order
ENDIF
STOP
• ITERATION – The program repeats the same instructions over and over. It is used when a set
of actions is to be performed repeatedly.
START <ProgramName>
DO <statement>
WHILE (<condition>)
STOP
START EatingPizza
DO eat pizza
WHILE (there is still pizza)
STOP
• KEYWORDS – These are specific terms or phrases used to represent fundamental operations
and control structures that guide the logic of the algorithm.
• They are not part of any specific programming language but are used to describe the logic in
a clear and structured manner.
• These keywords help to outline the steps of an algorithm in a way that is easy to understand
and translate into actual code later.
• In pseudocode, these keywords are used to indicate common input-output and processing
operations, and they are written fully in UPPERCASE.
PROBLEM 1
Create a program that inputs three numbers from a user and displays their average.
ALGORITHM FLOWCHART
PROBLEM 1
Create a program that inputs three numbers from a user and displays their average.
pseudocode
START DisplayAverage
SET sum = 0
SET average = 0
READ firstNumber
READ secondNumber
READ thirdNumber
CALCULATE sum = firstNumber + secondNumber + thirdNumber
CALCULATE average = sum / 3
DISPLAY average
STOP
PROBLEM 2
Compute and Print out the Sum, Average and the Product of two numbers.
ALGORITHM FLOWCHART
PROBLEM 2
Compute and Print out the Sum, Average and the Product of two numbers.
pseudocode
START SumAverageProduct
INIT sum = 0
INIT average = 0
INIT product = 0
OBTAIN num1
OBTAIN num2
DETERMINE sum = num1 + num2
DETERMINE average = sum / 2
DETERMINE product = num1 * num2
PRINT sum, average, product
STOP
Presentation by Jerico D. Quinzon
BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY (BSINFOTECH)
PROBLEM 3
Write a program that asks the user to enter a number and determines the
result, indicating whether the number is Positive, Negative, or Zero.
ALGORITHM FLOWCHART
PROBLEM 3
Write a program that asks the user to enter a number and determines the
result, indicating whether the number is Positive, Negative, or Zero.
pseudocode
START PositiveNegativeZero
READ num
IF (num > 0)
THEN DISPLAY num + “is positive”
ELSEIF (num < 0)
THEN DISPLAY num + “is negative”
ELSE DISPLAY num + “is zero”
ENDIF
STOP