Title: recursion
1????? 5 ????????
2????????????
- ????????????????????????????????
- ???????????????????
- ?????????????????????????????????????????
- ???????????????????????????????????????
(recursion)
3????????????????
- ????????????????
- ???????????????
- ??????????????????????
- ?????????????????????????????
- ??????????????????????????????
- ??????????????????????????????
4??????????????????
??????????????????? ??????????????????????????????
?????
Unstructured Programming
Procedural Programming
5Unstructured Programming
- ?????? ?????????????????????????????????????????
???? - ??????? ???????????????????????????
????????????????????????????????????????? - ???????????????,
- ???????????????????, ...
main program
6????????5.1 unstructured programming
include ltstdio.hgt main() int first, second,
third printf(\n F(X) 3X 10 if X gt 0\n)
printf(\n F(X) 10 if X 0\n) printf(\n
Enter 3 values\n) scanf(d d d, first,
second, third) if (first gt 0)
printf(F(d) is d, first, 3first 10) else
printf(F(d) is 10, first) if (second gt
0) printf(F(d) is d, second, 3second
10) else printf(F(d) is 10, second) if
(third gt 0) printf(F(d) is d, third,
3third 10) else printf(F(d) is 10,
third)
Code program ???????
????? first
????? second
????? third
7??????????????????? (????????????????????) ???
statement ???????????????????????????????????????
????????? copy ????????? ??????????????????????
????? statement ????????????????????? ????????????
??????????????????? ???????? Procedure
8Procedural Programming (1/2)
- ?????? ??? statements ??????????????????????????
???????????? main ??????????? procedure call
???????????????? ??? statements ???? - ?????
- ???????????????????????????????????????
???????????? main ????????????????????? - ??????????????????????????????????????????????????
??? - ?????????????????????????????????
????????????????? main ??????? procedures ??
9Procedural Programming (2/2)
- ???????? main ??????????? procedure
?????????????????????????????????????????
??????????????? main ????????????????????????????
procedures ?????????????????????????????? -
- ???? Procedural Programming ??????????????????????
???????????????? ???????? procedures ????????????
10????????5.2 procedural programming
include ltstdio.hgt void get_Fx(int x) main()
int first, second, third printf(\n F(X) 3X
10 if X gt 0\n) printf(\n F(X) 10 if X
0\n) printf(\n Enter 3 values\n) scanf(d
d d, first, second, third)
get_Fx(first) get_Fx(second)
get_Fx(third) void get_Fx(int x) if (x gt
0) printf(F(d) is d, x, (3x) 10) else
printf(F(d) is 10, x)
- ????????????????????????????????
- ????????????????? x??????????????????????????
11???????????????
- ???????? ???? Procedure ???
- ?????? statement ?????????????????????????
?????????????? - ??????????????????????????????????????????????
????
12?????????????? C
- ??????????? C ????????????????????????? (main)
??????????? - ?????????????????????????????? statement
??????????? - ???? C ???????????????? 2 ???
- ????????????????? C
- ??????????????????????????????????
FUNCTIONS IN C
PROGRAMMER DEFINED FUNCTION
C STANDARD LIBRARY
13C Standard Library
- ????????????????????????????????????????????? C
- ???????????????????????????
- disk I/O (input/output) ex. printf(), scanf(),
- string manipulation ex. strlen(), strcpy(),
- mathematics ex. sqrt(), sin(), cos(),
- etc..
- ??????????????????????? ???????????? include
header file - ???????????????????????? ????
- ????? printf(), scanf() ????????? include
stdio.h - ????? sqrt(), sin(), cos() ????????? include
math.h - etc.
14???????? 5.3 ????????????????? C
- ????????????????????? ?????????????? sqrt() ??
math.h - ?????? double sqrt(double num)
- ???????????????
- include ltstdio.hgt
- include ltmath.hgt
- int main()
-
- printf(f, sqrt(16.0))
15???????? 5.4
- ??????????? 10 ??????? 1 ??? 5 ???????????????????
pow() ?? math.h - ?????? double pow(double base, double exp)
- ?????? baseexp
- include ltstdio.hgt
- include ltmath.hgt
- int main()
-
- double x10.0, y 1.0
- do
- printf(f, pow(x,y))
- y
- while (y lt 6)
16??????????????????????
- ????????????????????????????? 2 ???????
- ?????????????? (function prototype)
- ????????????? (function definition)
- ????????????????????????????????
?????????????????????????????????????????? - ???????????????????? main ????????????????????????
????? - ???????????????????? main ????????????????????????
???????????????
17????????5.5 ????????????????????????? 1
function prototype
function definition
18????????5.6 ????????????????????????? 2