Title: 310222/310288 C Programming
1310222/310288C Programming
- ??????????????????????????
- ?????????????? ????????????????
- http//www.cs.buu.ac.th/krisana/310222
2Topics
- ?????????????????????
- ?????????????????????????????????? (Programming
Paradigm) - ????????????????????????????????????????
- ?????????????????????????????????????????????????
3?????????????????????????
- ??????????????????????????????????????????????????
- ??????????????????????????????????????????????????
??? (Programmer) ????????? - ??????????????????????????????? C
4?????????????????????????????
Storage
Input
Output
Processing
310322 C Programming
Department of Computer Science
5????????????????????????????????????????
310322 C Programming
Department of Computer Science
6?????????????????
- ???????????????????????????????????
?????????????????????????????????? ?????? - ????????????? (Algorithms) ??????????????????????
????????????????? - ??????????????????????????????????????????????????
????????????????????????????????????????????????? - Program ??????????????? (???????????????????????
???????????????????)
7??????????????????????????? (Algorithms)
- ??????????? (Algorithms) ??? ?????????????????????
????????????? ????????????????????????????????????
????????????????? - ??????????????????????? (Unambiguous) ???
?????????????????????????????????????? - ??????????????????????????????????????? ????
??????????????????????????????????????????????????
????? - ?????????????????????????????????????????????????
8???????????????????????????????
- ??????????????? (Input)
- ?????????????????? (Output)
- ???????????????????? ???? ?????????????????
(Assignment statement) - ???????????????????? (Condition or Selection)
- ?????????????? (Iteration or Looping)
9?????????????????????????????????? (Programming
Paradigm)
- Imperative paradigm ????????????????????????????
?????????? First do this and next do that - Functional paradigm ????????????????????????????
??????????????????????????????? - Logic paradigm ?????????????????????????????????
??????????????????????????? - Object-oriented paradigm ???????????????????????
??????????????????????????????????????????????????
? Object ??? ??????????????????????? Object
10Language Generation
- ??????? 1. ???????????(Machine Language)
- ?????????????????????????????
- ?????? 0,1
- ???????????????????????
- ??????? 2. ?????????????(Symbolic)
- ?????????????????????
- ???????????????????????
- ?????????????????????????? ???? ASSEMBLY LANGUAGE
310322 C Programming
Department of Computer Science
11Language Generation
- ??????? 3. ???????????? (High Level Language)
- ????????/???????????
- ?????????????????????????????
- ??????????????????????????
- ??????????????????????????
- ??????? 4. ???????????????
- ??????????????????????????????????????????? ????
SQL - ??????? 5 ????????????
310322 C Programming
Department of Computer Science
12??????????????????
- FORTRAN ?????????????????????????????????????????
?/???????? - COBOL ????????????????????
- PASCAL ???????????????????????? ?????????????????
- C ???????????????????????????????????????????????
????????????????? - C
- JAVA
310322 C Programming
Department of Computer Science
13?????????? (Language Translator) Interpreter
- ??????????????????????????????????????????????????
??????? (One Step Process) ????????
????????????????????????????????????????????
??????????????????????????????????????????????????
??? ??????????????????????????????????????
???? ???? HTML
14?????????? (Language Translator) Compiler
- ???????????????????????????????? 2 ??????? (Two
Step Process) ??? ???????????????????????????
Executable Code ??? ???????????????????????
Executable Code
(?????????????????)
????????????????????
15?????????????????????????????????????????
(Algorithms)
- ????????????????????????????????
- ??????????????????????????????????????????
????????????????? - ?????????????????????????????
- ?????????????????????????????????????????
- ???????????????????????????????????????????????
?????? ??????????????????????????? - ??????????????????????????????
- ????????????????????????
- ???????????????????
310322 C Programming
Department of Computer Science
16???????????????????????????????
??????? run01.c ??????? run02.c
main() int I0 while (Ilt3) printf(\nRunning No. d,I) I main() int I0 while (Ilt3) I printf(\nRunning No. d,I)
?????????????? run01.c ?????????????? run02.c
Running No. 0 Running No. 1 Running No. 2 Running No. 1 Running No. 2 Running No. 3
17?????????????????????????????????????????
(Algorithms)
- ?????????????????????????????
- ?????????????????????? (Pseudo Code)
- ?????????????? (Flowchart)
18?????????????????????????????
Algorithm ??????????????? Input
. Output .. beg
in ?????????????????????? ???? Comment of
Algorithm if condition then
.. else .. e
ndif case variable of condition 1
. condition 2 .
condition N . endcase for
start_condition to stop_condition step
do .. endfor while
condition do .. endwhile
repeat .. until
condition end
19??????????? 1 ????????????????????????????????????
????????????
Algorithm Triangle_Area Input ?????????? ???
???????????????????? ???????????????????????
????????????????????? ??????????????????????????
? Output ????????????????? begin
??????????????????????????????????????????? if
??????????????????????? then ???????????????
?????????????????????????? endif
???????????????????????????????????????? if
???????????????????? then ????????????????????
????????????????????? endif ????????????????????
?????????????? ???????????????????????????
??????? (1/2) ?????????????????????????????????
???? end
20??????????? 2 ????????????????????????????????????
????????????????????????????? 10 ??
???????????
21??????????? 2 ????????????????????????????????????
?????????????????????????? 10 ??
Algorithm Count_Sex Input ??? ??? M
?????????? ??? F ??????????? Output
??????????? ??????????????? begin ???????????????
?????????? ?????????????????????????? ??????????
???????????? while ????????????????????????????
?? do if ??? M then ????????????????
??????1 else ????????????????????????1 e
ndif ????????????????1 endwhile ????????????
????? ??????????????? end
22??????????????? (Pseudocode)
- ????????????????????????????????????? ???
??????????????????????????? - ????????? ????????????????????????????????????????
??????????? ????????????????????????????????????
???? - ???????? ?????????? BEGIN ?????????? END
- ???? ?????????????? READ ??? PRINT
- ??????????????????? IF , ELSE , ELSEIF
- ??????????? WHILE , DO ENDWHILE ???????
310322 C Programming
Department of Computer Science
23?????????????????????? (Pseudo Code)
- ???????????? ????????????
- read var1, var2,
- print var1, var2,
- ????????????????????? 2 ???
- if (condition) then
- true statement
- else
- false statement
- endif
- ???????????????
- case variable of
- a a-statement
- b b-statement
- endcase
- ????????????????
- WHILE
- While (condition) do
- statement
- Endwhile
- Repeat-Until
- repeat
- statement
- until (condition)
- Computation variableexpression/constant
24????????????????????? ????????????????????????????
?
- Input ?????????? ??????? base
- ??????? ??????? height
- Output ????????????????? ??????? area
- Begin
- 1. Read base, height
- 2. Compute
- area(1/2)baseheight
- 3. Print area
- End
25??????????? 4 ?????????????????
- ????????????????? ??????????????????
?????????????????? ??????? ?????????? 15 ??
??????????????? 20 ??????????????? Child
??????? 20 ??????????????????????? Adult
???????????????????????????? 20 ??
???????????
26Pseudo-code
Input ???? ??????? name ???? ???????
age Output ??????????????????? 20 ???????
less20 Begin 1. Repeat 2. read name, age
????? i 3. if agelt20 ????????? name ???
Child ???????????????????????????????? 20
else ????????? name ??? Adult
endif 4. until (???????????? 15 ??) End.
27???????????
Algorithm Compare_Age_Algo Input ???? ???
???? Output ??????????????????? 20 begin
count less20 0 While (countlt15)
do read name, age If (agelt20) then
print name, Child
compute less20less201
Else print name, Adult
Endif compute
countcount1 Endwhile Print
less20 End.
28?????????????? (Flowchart)
- ??????????????????????????????????????????????????
?????????? ???????????????????????????????????????
???
??????????????????????? (flowlines)
???????????????????????? ???????????
????????????????????????? (Input/Output)
???????????????????????? (Processing)
310322 C Programming
Department of Computer Science
29?????????????? (Flowchart)
???????????????????????? (Decision)
??????????????????????????????????????????
(Connection)
???????????????????????? (Predefined Process)
?????????????????????????????????????
(Repetition)
310322 C Programming
Department of Computer Science
30?????????????? (Flowchart)
???????????????????????????????
???????????????
???????????????????????? ???? ?????
310322 C Programming
Department of Computer Science
31(No Transcript)
32????????????????????
- ???????????????????????? ?????????????????????????
??????????????????? - ?????????????????????????????????????????
???????????????? - ?????????????? ?????????????????????
?????????????????????????????? ???????????????????
????????????????????????? - ???????????????????????? ???????????
- ?????????????????????????????????????????????
?????? ????????? ??????????????????????
33????????????????? ???????? 3 ??????
- ???????????????????? (Sequence)
- ??????????????????????? (Selection)
- ???????????????????????????? (Iteration)
34???????????????????? (Sequence)
35??????????????????????? (Selection)
????????????????????????????????? ????????????????
?????????????? 2 ????????
?????????????????????????????????????????
36???????????????????????????? (Iteration)
????????????????????????? Do-While Loop
37????????????? ?????????????????????????????
38?????
- ??????????????????????????????? ???????
?????????? 15 ?? ??????????????? 20
??????????????? Child ??????? 20
??????????????????????? Adult
???????????????????????????? 20 ??????? 20 ??????
39(No Transcript)
40????????????????????????????
????????? ????????
???
- ??
???
/ ???
???????
????????? ????????
gt ???????
lt ????????
gt ??????????????????
lt ???????????????????
ltgt ??????????
310322 C Programming
Department of Computer Science
41?????????????????????????????
P Q P AND Q P OR Q NOT P
T T T T F
T F F T F
F T F T T
F F F F T
42??????????????????? C
310322 C Programming
Department of Computer Science
43??????????????????? C
- 1. ?????????????????????????????????? ???? vi
???? pico ???????????????????? ? ??????????? - 2. ??????????????????????????????????????????
- ??????????? (.obj)
- 3. ?????????????????? ? (link) ???? Linker
- ??????????????????????
- ???????????????????
- 4. ????????????????????????????????
- (Execute File)
310322 C Programming
Department of Computer Science
44??????????????????
- 1. ??????????????????????????????????????????
- ????????????? ???? Harddisk ???????????????
- ???????
- 2. ??????????????????????????????????????????????
- ???????????????????????????????????????
- ???? ???????? ????????? (fetching)
- 3. ??????????????????????????? ???????? ?????????
- (Decoding) ???????????????????????????????????
???? - ???????
310322 C Programming
Department of Computer Science
45??????????????????
- 4. ????????????????????????????????
???????????????????????????????????????????????
???????? ???????? ??????????? (Executing) - 5. ???????????????????????????????????????????????
?????????????????????????????????????????????????
310322 C Programming
Department of Computer Science
46(No Transcript)
47??????????????????????????
10, 12
22
Unit
ALU
Control
10
INPUT A,B
12
X A B
PRINT X
22
END
INPUT A,B X A B PRINT X END
RAM
A
B
X
INPUT A,B
12
10
22
X A B
PRINT X
END
Work Area
Program Area
???????
48??????????? C
- ??????????????????????????????? C ????
- ??????????????????
- ??????????? C ????????????????????????
- ????????????????????????? ? ???????????
- ????????????????????? C ???????????????
- ??????? ANSI C
310322 C Programming
Department of Computer Science
49??????????
- ?????????????????????
- http//www.cs.buu.ac.th/310101/pdf/l2.pdf
50310322 C Programming
Department of Computer Science