You are on page 1of 16

instruction a ดแแนะ น

a x caked = ด เ นการ

What is a computer program


set of instructions that be exented by
·- a can a
computer
to perform a specific house

program langeges Ex.


Python
We will study & language

@ x cutable

-Source for Re

object file

1. Every must have function main


progath
2. Every statement ends with

comment

=>

commenting

ยื

นิ
escape Sequence : sequence of

Characters that dose not represent it sarf

Types of data data/ BrE) singul


7.2
1-
denary numbers data/ Ame) plutal
base - 10 intergens -
5800 อ

2. floati point number s 13.67 2.50


2

by
(base -
- decimal
10 decimal numbers/ +เ า
point
1.742E5 20.8: floating point number
=1.742x185

3.
Octal number
base - 8 intergars) 074 0115 02
-start with o

4, hexa decimal numbers


base- 16 intergens) ex. 0-
9, 9, D, , d,ef 0x14 = OX5
t

20

-start with Ox

5 , characters
- letters of
symbols p' ' ' In'
-must be in single photos
6.
string S

"Eves"
is

- sequence of characters prompony"


/

duble
↳ก
-must be in
quotes 9394

ASCII : American Standard code


จ้
format &

of pecifier
1. 1. d- denary numbers

a. Y. f. floating - point numbers ( 6 decimal points by default)


3.1.2 - characters

Variables : memory slots used to store data in a


progarm
int - Infeg eh

float - floating- point numbers

char- character S

to use a
variable, we must declare it frist.

1. tipe name; int height;


2, type name = value int
height = 182
3.
Type namel, namee, ... int height = 102, lenght;
Declare variables before other instructions

Rules for having variable


1เ 1 +o 255 characters long
2. Must begin with an alphabet on an under score 7
3. Can contain only alphabets, gigits and Underscones
4. Variable names arecase - sensitive

b. Cannot use a reserved word as a variable name into return


6. don'tstart with digit
=: varVar/↳ Var &
svAR, rAR, VAR are all difference

9. don't
keyword Bat เ ยน ให ไ

Assignmentstate ment
- use to assign value to variable
1= x becomes P' VC,
3; -

X= 5; not an equation.
light speed = 300000000

1. Declare a variable to store the radius of given d

Anithmetic calculation

arithmetic operators meanings examples descriptions


#

addition a -
bic; Add a to band store

subtraction a bee;
theysee
thefrom the and
stone the difference in a
-

multiplication bec by a and


be
* at
multiply
stone duct
the # in a

/ division ab/ c; Divide b


by and
a

stone the fent in a


quo
/ modu Mo b/ Divide b
:

C; by and
a = a

Operation Stone the remainder in a


ตั
ขี
ด้
ญ่
Divi s เฉก
1. Perform division using the magnitude of dividend and the divisor
You get the patients.
2. If the
signs of the dividend and the division are the

same, make the quotient positive. Otherwise, make the


quotient negative
↳ผลหาร

* 3/ 3 = 73)/ 3 = -1

5) ( 3) = - /3) :
Modulo operation
divienda divisor * quotient a
remaindet
Ex 5/. 3 -> 3 = 3*+ remainder - > SY. 3 = 2

ES)". 3 - > - >= 3 ( - remainder - > (- 5)y, 3 = -2


1)
5 1.53) -> 5 = 3/ 1/1) the main der > 0%. 3= 2

(S) 1. (-3) -> -


S =
73*1 heminder -> (S)1.73) : - 2

Compound orithmetic operator s

+= addition and assignment at =b; <> abi


d=

-= subtraction - 1) - a- = b; -> a = a-
bi
* = multiplication
/ -- ak= b; <-> d=
adb;
/= division - 11 - a/b; ==> a=
alb
~> = modulo operati on - 19 - 0% = b ; <- > a= b;
a/

Increment and decrement operators


as Gt =
It increment by one
ata; ted; 1;
-- decrement by one a --;--d; <> G-=
1,
Q : + +b; in crement than n -> become
a =
bet; ↳ then
assign -becometrement

↓a = b , +1
bxไ aabt Operators that

↑ take
&
Rule > of
operations a wo

1. Left to
right for binary
Operators operand
2. Right to let for t

unat↳ operators - > operations that


·x > /
+ 1a Ka

·parand
One
Avoid combining single arithmetic operators I
compound anithmetic operations, and increment
and dectement operations.

x: attab /

Getthe
1= G*
bXtra; Depending on

compliens
Use parenthesis (

Logical operation and expressions


avalue

· ช
-

Logic -> TRUE FALSE - ↑อ


/
/
&
nonzer จ number zero AscileO
TRUE -> value:& 10,000...)
integer *
One /
one of operands pat Operator

Relational
#a
operators
== is
equal to a = b that if a is equal to b
/ heb TRUE
9 = is not equal to a if a is not qual to b
a

< is less than a a b true if a is less than b


= is less than or
equal to a set that if a is less than or equal to b
> is more than as b TRUE if a is more than b
<= is more than or
equal to a >= b TRUE if a is more than on equal to b

&4 and a da b TRUE if a and bartrue


1 on allb Tale of cord is ture
dp
/
not & tave it a is false

Logical expression แ วจ าง
&4/ 1 * P-P P= P
(
<

use
①not parentheses
pot P
ตั
ม่
ค่
of
Order
operations ( revisted
* * - & Lunary operators)

&
* , "

Use parenthese
< <= > > =
to avoid confusion
= =
:

& &

"

ssignment
Input/ Output functions

prints int

of
-> address
the

add
prompt message
Short cat evaluation
is jus
ex . (itsof a litt
Civic of 11 littl
result
je2, i=
S

Conditional statements

②If statements
1. Yif condition

free
of
the

amenities
i

fake

2.
if ( conditions

monfiltra
3

#
3. If I condition

↓ true

(entire
>integr go to number

& -

false,

( )

add

fansell number
If

Error ,testing and debugging 3. Undected ennors =


programs
can run to completion but
give inconnect result

Types of errors -whong format specifiers


Pio
1.
Syntax errous = Rating %6 . C

rules
grammar -missing &
variables
Emissing; - undeclared 4. Logic entors =
programs
-whong variable names follow fanity algorithms
- unbalanced parentheses Whony placement
Ex.- of braces

(CK ( 117) - incorrectdesign


Runtime errors = detected Testing = checking thata given
program
2.

during execution works


correctly and matches expected requirements
Ex- division by zers 1+ 2 = 3

- segmentation fault & you


can test a
program by Inputting fast cases

-sout of negative numbers A test before sending to teacher eim

Type of
tasting
1. Black - box testing - without looking at the code
Debugging Advantage
buy (a) error a computer program.
of thechatting case will less likeli
conrelate
debug (v) find and remove
bugs with the code
Test
flow to debag a
program disadvantages 1.
may not cover all
1.
Input test cases thatgive known possibilities
out puts 2. Glass box
testiny - with looking at the code
2. Add diagnostic calls to print
f

Advantage to seeing the program flow can

to displays value at points in catch more erhOnS

the programs
disadvantages so fast cases will more likely
correlate with the code
Internative statement
1. While state mont # ดะไ ตะใค

ท 2. do- while statement + ท ง

While ↓อ
condition ()

/ ↓ &
' stor :

to menti
:
ก าเ ยนค ง ไ อน

pations
3 white

<

false

for
t

3. state men
3.1
for ( state monte,
--
condition, statement); -

false
·

sum: samt
i
#I to
can use program

floor
5
ตลองาน
ผิ
ดี
ก่

ขี


ม่
ว้
ว่
สั่
รั
ปั
ผิ
1. break terminates the loop * 8 = false
olse = true

#
3.2 for ( stement -condition,
:

statement - int

!emanticf/
-

itunes
2. continue things the program control false }
to the beginning of theloop. In the
if forces the next
other words,
itenation of the loop

num/e = 1 : 2
Array s

Array = collection of two or more

continuous memory cells

Variable in the same


away one
of the same name
any type

How to declare
type name sizes's
EX
float value SJ; -

-value - This is
array
one dimensional

continuous
2P type name now) dumms;
Id. JIdal... hut ;
-

type name

Array intralization
type, namesize = values, values, ... , value- size:
type nowcolumns = values, values, ... ,value.column as, value- columntzc
name

... , Value column * Low


If the away is initialized but notevery element is
initialized, the value of

uninitialized element become 0.

Referencing array elements


refer to each element subscript. In ID that has
We in an away by a
array
n elements, the first element has the subscript of a and the last element has
the subscript of not
float value S
Value of value 1 value2 varue3valueInt

type name inf


ohnay ·
name of
=0

/ "ว 4

name of namen-1j
ที่
ตั
On
my body on
Searching and sorting an auto

seauching
INPUT : an array a
of numbers and a number
OUTPUT: If the number is found
·print
the indices of the cell where the number

is found. Otherwise, print Not found

sequential Search = thaversim achay


I am

every element
sequentially and check in it.

ทะ เบ

0 1 2 3 4 5 6 -> 8 9

16 5- 2011 14 15 1 -
·9

Search for 15

found at all no. S

Search for 10

Found at all no. 3

Found at card no. G

search for - B

Notfound

Searching and sorting an annou Ex n = 10

souting : 0 1 2 3 4
5 6 7 · 9

INPUT : an away of a numbers


⑧น ↑
-

-- ช
6- 5 9 - - G 13 01 4

OUTPUT: the array of numbers where


a min
all the numbers are arranged in order -8 . . . - 8
minpos
Selection Sout = repeatedly finding the
88** ** $... xg
of
minimum ( image ascending order) element
from the unsouted part and putting it tomp
at the
beginning . .
short , * write name **, write clean t

* don'tput comme on
space in out put
No electric

can bring Notes,sheet, Text door, Dic

Read the question came fully

Problem in the back easier

You might also like