Title: 1204 102 Problem Solving
11204 102 Problem Solving
- ???????? ?????????????????????????????????????????
?????
2???????????????????????? (String)
- ??????????????????????????? (char)
- ???????????? ?????????????????? ???????? ???
????????????? Array ?????? - ?????? 1 (??????????????????????????????????????)
char ???????????????????????1 - ?????? 2 (?????????????????????????????) char
?????????? ??????? - ?????????????????? ???????????????????????????????
????????????????????? (??????????? Double
Quote) - ???????????????????????????????????? ??????
- ?????????? ???????
- ????????????? ?????????????1
??????????????????????????????????????? ??????
\0 ???????
3Library ?? Header File
- ???????? ??????????????????
- www.cppreference.com/index.html
- en.wikipedia.org/wiki/C_standard_library
- www.utas.edu.au/infosys/info/documentation/C/CStdL
ib.html - ????????????????????????????? ??????????????
Header File ?????????? Include - include ltstdio.hgt
- ??? Library ????????? Standard Input/Output
- include ltconio.hgt
- ??? Library ????????? Console Input/Output
- include ltmath.hgt
- ??? Library ??????????????????????????????
- ???
4stdio.h
- printf() ?????? ???????????????????????????
- scanf() ?????? ?????? Input ???????????? keyboard
- gets() ?????? ?????? String ??? keyboard
- puts() ?????? ???? String ????????????
- getchar() ?????? ?????? Character ??? keyboard
- putchar() ?????? ??????? Character ????????????
- ???
5???????? scanf, printf, ???????????
6??????????? String ????????????
????????? char name20 ???
name1Algor ???????????????? name ??????
???????????????? ????????? ???????????????????????
? ??? ???? ?????????????????????????? ?????????
scanf(s,name) name1 ?????????????????????
?? ??????? Algor ???????????????????????????????
???????? ????????? printf(K.s ..,name1)
7??????????????????????????????????
??? flowchart ??????????? ?????? 2 ??? WIDTH,
LENGTH ??? ???????!! ????????????????? ???????
???????????????????? ???????????? scanf
???????? ????????????????????????
??????? ?????????????? ??????? ??????
printf ???? ????
Output
8????! ????????????????
- ?????????????????????????????????????
??????????????????????????????? 30
???????????????? ??????????????????????????? 3 ??
????????? ??? ???????????????????????????
???????????????????????????? - Flowchart ?????????????????
?????????????????? (bonus)
mom bonus x 0.3 children (bonus mom) / 3
???? ??????? ??? ??? ???? ?????? (mom, children)
9Flowchart ??? Source Code
?????? ????????????????????????? float
includeltstdio.hgt includeltconio.hgt int main()
float bonus,mom,children
printf(Input Fathers bonusgt ) scanf(f,bon
us)
mom bonus 0.3 children (bonus mom) / 3
printf(Mother gets .2f, Children get
.2f,mom,children)
?????? printf ????? ??????????????????????
?????????????? ??? printf ?????
???????????????????? mom ??? children ??????????
??????????????????????????????????? ????
????????????????????????????????
10????! ???????????
11conio.h
- getch() ???????????? character ??? keyboard
??????????????????????????? - clrscr() ??????????????????????????????
- clreol() ??????????????? ? ??????????? cursor
- ???
- ??. ??????????? ?? Dev-C ???????????
- system(cls)
-
????????? Header file ???? - ???????????
iostream.h ?????????? - system(pause)
???????????
12???????????? cls ??? pause
13???????????????????????????
- ????????????????????????????????????????
(Keyboard) ??????????? ???? - ?????? getch() ?????? conio.h
- ?????? gets() ?????? stdio.h
- ?????? scanf() ?????? stdio.h
14getch()
- ????????????????????????? 1 ????????????????
???????????? Enter ???????????????????????????????
? - ????????????????????????? ASCII ????????????
- ???? include ???????? conio.h
- ??????????? 2 ???
- ??????????????????????????????? ???????????
- char ch
- ch getch()
- ????????????????????????????? (???????????????????
Key ??? ??????????????) ??????????? - getch()
15Example 11
- include ltstdio.hgt
- include ltconio.hgt
-
- int main ()
-
- printf("Press any key to continue\n")
- getch( )
-
- char ch
- printf("Input one character ")
- ch getch( ) //????????????????????????????????
??????????? - printf(\nYour character is c", ch)
-
16gets()
- ???????????????? (String)
- ???? include ???????? stdio.h
- ????????? ???????????????????????
- char ??????????????????????????????1
- gets(????????????????? )
- ????????
- char name10
- gets(name)
17Example 12
- include ltstdio.hgt
-
- int main()
- char name10
-
- printf("Input name ")
- gets(name)
- // printf("Hello s\n",name)
-
- return 0
-
????????? comment ??????????? 8 ??????? run
???????? ??????????????????
18scanf()
- ???????????????????????? ?????????????????????????
- ???? include ???????? stdio.h
- ?????????????????????????? ??????
- //
??????????? - ??????????????
- d ???/?????????????????????????
- f ???/????????????????
- c ???/????????????????? Enter (??????????????)
- s ???/??????????? (String)
- ld ???/??????????????????? ??????????? 4
???? - lf ???/????????????????????? ???????????
8 ???? - argument
- argument ??? ?????????
- ??? ?????????? address ?????????????????????????
???????????
scanf(??????, argument)
19Data type long , double
?????? ????????????????????? ??????? ????????
?????????????????????????? ??? ????????????
??????
20ld, lf
21Example 13
- include ltstdio.hgt
- include ltconio.hgt
- int main()
- char ch
- char name10
- int num
- float score
- printf("Input one char ") scanf("c", ch)
- printf("Input string ") scanf("s", name)
- printf("Input integer ") scanf("d", num)
- printf("Input float ") scanf("f", score)
- printf("char(c) string(s) integer(d)
float(f)", ch,name, -
num,score) - getch()
- return 0
-
- ??. s ???????????? scanf ????????????????????????
???????????? gets ??????????????
22Example 14 (???????????????????????????? 13)
- include ltstdio.hgt
- int main()
- char ch char name10
- int num float score
- // ?????? Input
- printf("Input one char ") scanf("c", ch)
- printf("Input string ") scanf("s", name)
- printf("Input integer ") scanf("d", num)
- printf("Input float ") scanf("f", score)
- // ?????? Output ??????????????? Input
???????????? - printf("Display one char is c\n", ch)
- printf("Display string is s\n", name)
- printf("Display integer is d\n", num)
- printf("Display float is f\n", score)
- return 0
23??????????????? scanf, gets
?????? ??????????????? ???? ???? ??????????
??? ?????????????? scanf(ss,name,
surname) gets(name) ???????????????????
? ?????? ??????????????? ???? ????????????????????
????????????????? ???????????????????
24Example 14
- include ltstdio.hgt
-
- int main()
- char ch
- char name10
- int num
- float score
-
- printf("Input string ") scanf("s", name)
- printf("Input one char ") scanf("c", ch)
- printf("Input integer ") scanf("d", num)
- printf("Input float ") scanf("f", score)
-
- return 0
?????????????? 13 ????????????? ??? 9 ??????
10 ?????? ????????????????????????? ??????????????
??????????????????
25math.h
- ???????????
- abs()
- ??????????? absolute ?????????????????????
- fabs()
- ??????????? absolute ?????????????????????
- exp()
- ????? exponential
- fmod()
- ?????
- log()
- ????? natural logarithm
- log10()
- ????? logarithm ??????
- pow()
- ???????????????
- sqrt()
- ??????????? 2 (square root)
- ????????
- int ?????? abs(argu)
- float ?????? fabs(argu)
- float ?????? exp(argu)
- float ?????? fmod(argu)
- float ?????? log(argu)
- float ?????? log(argu)
- float ?????? pow(??????, ????????)
- float ?????? sqrt(argu)
26Example 15
- include ltiostreamgt
- include ltconio.hgt
- include ltmath.hgt
-
- int main()
- printf(Press any key) getch() //
????????? ??? keyboard - system(cls) // ????????
- int a, b, c // ???????????????
- printf(Input a ) scanf(d, a) //
?????? a - printf(Input b ) scanf(d, b) //
?????? b - printf(a d\nb d, a, b) // ??????? a
??? b - cabs(a) // ????????????? a ??????????????? c
- printf(Show absolute of a d\n, c) //
??????? c - printf(Show absolute of d d\n, a, c) //
??????? c - cpow(2,3) // ????? 2 ??????? 3
??????????????? c - printf(Show 2 power 3 d\n, c) // ???????
c - cpow(a, b) // ????? a ??????? b
??????????????? c - printf(Show d power d d\n, a, b, c) //
??????? c - getch()
27Example 16
- include ltstdio.hgt
- include ltmath.hgt
-
- int main()
- float x, y, z
-
- printf("Input x ") scanf("f", x)
- printf("Input y ") scanf("f", y)
- printf(" x f\n y f\n", x, y)
- zfabs(x)
- printf("Show absolute of f f\n", x, z)
- zpow(x, y)
- printf("Show f power f f\n", x, y, z)
- zsqrt(x)
- printf("Show square root f f\n", x, z)
-
- return 0
-
28?????????
- ?????????????????????????????????
- ??????????????????????????????????????????????????
???? 10 ??? ??????????????? 5 ??? ??? 10 ???
??????????????????????????????????????????????????
??????? ????????????????????????????????????
??????????????????????? - ??????????????????????????? ???????????
??????????????????????????????????????????
??????????????????? (1 ??? 400 ???????) - ?????????? ???? ????? ?.?. ???????????????????????
???????????? ???????????????????????????? - Name Surname, Birth Yearxxxx
- Your age is xx
29?????????(???)
- ?????????????????????????????????????????????????
- P(x) x5 3x4 2x3 x 6 ????? x
?????????????????? ????????????????????????? - ??????????????????????????????????????????????????
???????? R ??? H ??? ???????????????????
???????????????????? - ????????????????xx.xx ,
???????xx.xx - ????????????????xxx.xx
- f(x) x5 5x 8 ???????? x 3
- 3x2