Lecture 1c Update
Lecture 1c Update
COMPUTER
PROGRAMMING
Lecture 1c
Lecture Outline
■ Programming Fundamentals
– Input, Processing and Output
– Variables
– Data types
■ Basic Operators
– Arithmetic
– Comparison
– Assignment
– Logical
– Bitwise
Programming Fundamentals: Input
■ Data entered into a program, either by the programmer or
digitally, are referred to as inputs .
■ This is where the data from the program is shown to the user,
either on screen or in the form of a physical output such as
printouts or signals.
Programming Fundamentals: Input
■ The input operation in a program transmits data from an
outside source to the program.
■ Often this data is typed at the computer keyboard by the
person using the program. The program waits until the
user types something.
■ This action is referred to as entering data from the
keyboard.
– We will use a statement that begins with the word
Input to allow the user to enter data from the keyboard
Obtaining user input from a keyboard
■ A program will require a computer system to perform four
main actions in order to communicate with a user:
■ The ways that specific words and symbols are used by each
language is called its syntax.
– The actual code depends on what language you are using.
Every language has its specific syntax
The difference between syntax and
semantics in computer programming
■ Syntax refers to the structure of a program written
in a programming language.
■ P – Parentheses [{()}]
■ E – Exponents (Powers and Roots)
■ MD- Multiplication and Division (left to right) (× and ÷)
■ AS – Addition and Subtraction (left to right) (+ and -)
Solution:
As per the PEMDAS rule, first we need to perform the operation of exponent,
i.e. square root
For this first we need to add the numbers under the square root.
Example 4:
Calculate: [25 + {14 – (3 x 6)}]
■ Solution:
■ Given,
■ [25 + {14 – (3 x 6)}] As per PEMDAS, here we have perform the
operations within the parentheses, first (), second {} and finally []
■ =[25 + {14 – 18}]
■ = [25 +{-4}]
■ Here, we have to perform multiplication for the signs
■ = 25 – 4
■ = 21
Example
■ Given the arithmetic expression: 6 + 8 / 2 * 2ˆ2
1. 6 + 8/(2 * 2ˆ2)
= 6 + 8/8 = 6 + 1 = 7
2. (6 + 8)/2 * 2ˆ2
= 14/2 * 4 = 7 * 4 = 28
3. (6 + 8)/(2 * 2ˆ2)
= 14/8 = 1.75
PEMDAS: Order of Operations
■ P: Solve the calculation or equation which are present in the
parentheses or brackets like small brackets( ), curly brackets{
} or big brackets[ ]. Priority is given to brackets first.
■ E: Exponential expressions should be calculated first before
the operations of multiplication, division, addition and
subtraction. Usually, they are expressed in power or roots, like
22 or √4.
■ MD: Then perform multiplication or division from left to right,
whichever comes first in the equation.
■ AS: At last, perform addition or subtraction whichever comes
first while moving from left to right.
PEMDAS Vs BODMAS
■ There is only an abbreviation difference between them.
1. https://www.bbc.co.uk/bitesize/guides/zfnny4j/revision/9
2. https://www.computerhope.com/jargon/p/processi.htm
3. https://byjus.com/maths/pemdas/