Title: 1 Introduction to C Programming Language
1????? 1???????????(Introduction to C
Programming Language)
2??????????? (Programming Languages)
????????????? ??????????????????????????????????
??????????????? ?????? ????????????????????
? ????????????????? ?????????????????
??????????????
31.1 ?????????????????
?????? ?????????????????? ????? (Dennis Ritchie)
??????????????????????????? (UNIX)
???????????????????? DEC PDP-11 ?????????????????
??????????????
41.2 ???????????????????
- ??????????????????????????????????????????????????
?? - ???????????????????????????????????????? ????????
???????? (Function)
5??????????? 1.1
- include ltstdio.hgt
- void main( )
- / Display message to standard output
/ - printf(My first program.)
-
- ????????????????????
- My first program.
6?????? 1.1 ????????????????????????
include ltstdio.hgt void main( ) /
Display message to standard output /
printf(My first program.)
7???????? 1.2
- include ltstdio.hgt void main( ) /
Display message to standard output /
printf(My first program.) -
8???????? 1.3
- include
- ltstdio.hgt
- void
- main
- ( )
-
- / Display message to standard output /
- printf(My first program.)
9- ??????? 1.1 1.2 ???? 1.3 ??????????????????
- ??????????????? ??????????? ????????
- ???????????????????????????? (Indentation)
- ??????????????????????????????????
- ??????????????????????????????? (Space Bar)
????????? 3-5 ??
101.3 ???????????????????
- ????????? ???????? ????????????????? ???
- ????????????
- ?????????????????
- ???????????????
- ?????????????????????????????????????????
- ???????? ?????????? (Variable) ???????????????????
?????????????
111.3.1 ??????????
12 ???????????????????????????? ??? 3 ????
- ?????????
- ?????????
- ????????????????? (String)
13??????????????? 10 ???? 125 0 -154
??????????????? 8 ?????????????? 0 ????
0377 0177 0000 01 ??????????????? 16
?????????????? 0x ???? 0X ???? 0XFF 0x14
0x4B?????????????? long ????????????? l ????
L ???? 123L 0437l 0x4FFL
????????? ???????????????? int, short, long,
unsigned int, unsigned short ??? unsigned long
14????????? ??? ?????????????????????????
???????? ?????????????????????????????????
???????????????? float ??? double
- ????????????????? ???? 12.524 0.1259 0.00001
- ???????????????????????????? ???? 1.0E4
12.432e-4 1E-4 2E3 - ?????????????? float ???? 1.4321F 472.324f
- ?????????????? double ???? 232.98D 1.2323d
15????????????????? (String) ????????????????
char ????????????????? 1 ??????
???????????????????????????? char (Array of
char) ??????????????????????????????????
- ????????????? ???? a W \a \t
- ????????????????????????? \ ??????????????????????
- ???? \a ??????????????
- \t ?????????????
- \n ????????????????????
161.3.2 ????????????
- ??????
- ???????????? ??????????
- ????????
- float score
- int age
- char ch
- float width, height, length
17?????????????
- ??????????? a ??? z
- A ??? Z
- ??? 0???9???_(Underscore)
- ????????????????? ?????????????????????? ????_
- ????????????????????????????????? (Keyword)?????
- ????????????????????/????????????????????
18?????? (Keyword)
- auto double int struct
- break else long switch
- case enum register typedef
- char extern return union
- const float short unsigned
- continue for signed void
- default goto sizeof volatile
- do if static while
19????????????????????
- ???????????????????
- ??????????????????????? ??????????????????????????
??????? - ?????????????????????????????? ???????????????????
???? - ??????????????????? define ??????????????????????
????????????? - ?????????????????????????? ? ??
??????????????????????????????????????????????????
??????_ ???????????? ???? totalScore ????
total_score
20??????????????????
- salary _MAX
- MONEY Average_score
- x totalPage
- recordno annual2001
21?????????????????????????????????
float dollar int my age integer
age int a. b. c char
ch float student-height float
1Score
22???????? ??????????????????????????????? ??? int
sum0 float height0.0f
231.3.3 ???????????????????????????
- ?????????????????????? ??? ???????? scanf( )
- ???????????????????????????????????? printf( )
- ???????????????????????????????
- include ltstdio.hgt
241.3.3.1 ????????????
- ??????
- scanf ( ?????? , ????????????1,
??????????2,..) - ??????????????????????????????????????
- ?????????????????????????????
????????????????????? - ????????????????????? ?????? (Format code)
????????? - ?????????????????????????????????????
25????? 1.2 ??????????(Format code)???????????????
- d, i ??????????????????????????????????? int
- ld ??????????????????????????????????? long
- u ??????????????????????????????????????????
unsigned - o ???????????????????????????????8
????????????????? unsigned - x ???????????????????????????????16
????????????????? unsigned - c ??????????????????? 1 ???
- s ??????????????????
- f ???????????????????????????????? float
- lf ???????????????????????????????? double
26????????????????????????
- ????????????????? ??? Format code ??????
???? - d s ?????? ??????????????????????
- ?????????????????????????????????????????
- ???????????????????????????????????????
27- ???? ????????????????????????????????
- ?????????
- int month, year
- scanf (d d, month, year)
-
28- ????????????????????
- scanf (d/d/d, day, month, year)
- ??????????????????????????
- 20/7/2001
-
- ?????????????????????????????? ????
- scanf(2d2d4d, day, month, year)
- ?????????????????????????????
- 20072001
291.3.3.2 ???????????????
- ??????????? printf( )
- ??????
- printf(Control, Argument list)
- printf (??????,??????????1,??????????2,.. )
- Control?????????? ???????????????/??????(Forma
t code) - ????????????????????? ????????????????????????????
????? - ??????????????????????????????????????????????????
- ?????
30????? 1.3 ?????? (Format code)????????????
- ?????? ?????????????????
- d, i ???????????????????????????????? int
- ld ???????????????????????????????? long
- u ???????????????????????????????????????
unsigned - O ??????????????????????? 8
????????????????? unsigned - x, X ??????????????????????? 16 ????????????????
unsigned - c ???????????????? 1 ???
- s ???????????????
- f ????????????????????????????? float
- lf ????????????????????????????? double
31- ????
- char name Mickey
- int age 20
- printf(s is d years old., name, age)
-
???????????????? Mickey is 20 years old.
32- ?????????????????????? ? ???????????
- printf(Good morning.)
???????????????? Good morning.
33- ???????? ?????????????????????????????????
- int x, y
- x 7
- y 2
- printf(The sum of d and d is d\n, x, y,
xy) -
???????????????? The sum of 7 and 2 is 9
_
34- ???????? printf( ) ?????????????????????????
- ????????? ????????????????????????? ?????????????
- ????
- printf(The sum of 5d and 5d is 5d\n, a, b,
ab)
????????????????????? The sum of 7 and 2
is 9 _
35???????????????????????????????????
- ????????????? ????????????????????????????????
?????????? ??????????? - ??????????? ?????????????????????
- ????????? ???????????????????????
????????????????????????????????? - ????????????????????????????????????????? ???
Format code
36- ????????
- float x43.34, y2.231
- printf(Minus f with f, answer is f, x, y,
x-y) - ?????????????????????
-
-
-
Minus 43.340000 with 2.231000, answer is
41.109000
??????????? printf(Minus 4.2f with 4.2f,
answer is 4.2f)
????????????????????? Minus 43.34 with 2.23,
answer is 41.11_
37?????????????????????????????
??????????????????????????????????????????????????
???????????
- ??????????? 1.5 ?????????????????????????????????
??? - include ltstdio.hgt
- include ltconio.hgt
- void main( )
- clrscr( )
-
38 Computer
- printf("\ns", "Computer")
- printf("\n2s", "Computer")
- printf("\n.3s", "Computer")
- printf("\n10s", "Computer")
- printf("\n-10s", "Computer")
- printf("\n-10.3s", "Computer")
- printf("\n")
-
-
Computer
Com
Computer
Computer
Com
39- Printf("\nd", 100)
- printf("\n.2d", 100)
- printf("\n10d", 100)
- printf("\n-10d", 100)
- printf("\n-10.2d", 100)
- printf("\nf", 32.5762)
- printf("\n.2f", 32.5762)
- printf("\n10.2f", 32.5762)
- printf("\n-10.2f", 32.5762)
100
100
100
100
100
32.576200
32.58
32.58
32.58
40- ??????????? 1.6 ???????????????????????????
- include ltstdio.hgt
- void main( )
- char name100
- printf("What is your name ?\n")
- scanf("s", name)
- printf("Very glad to know you, ")
- printf("s.",name)
-
-
-
?????????????????? What is your name
? Willy Very glad to know you, Willy.