Title: ' "
1???? ????? ?????? ?' ???"?
????? ????? ??????? ???????
www.cs.tau.ac.il/armon/cprog08a.htm
2?????? ?????? ??????? ?? ??? ????
- includeltstdio.hgt
- int main()
-
- int i ,j, a1111
- for(i1 ilt10 i)
- for(j1 jlt10 j)
- a i j ij
- for(i1 ilt10 i)
-
- for(j1 jlt10 j)
- printf(4d, a i j )
- printf(\n)
-
????? 1 2 3 4 5 6 7 8
9 10 2 4 6 8 10 12 14 16 18
20 3 6 9 12 15 18 21 24 27 30
. . .
?? ????? 4 ????? ?????? ?? ???? (??? ?? ????
????? ???? ????? ??????)
3????? ?? ???? ??????? ?????
???? ??????...
- includeltstdio.hgt
- int main()
- int i,j,a1111
- for(i1ilt10i)
- for(j1jlt10j)
- ai jij
- for(i1ilt10i)
- for(j1jlt10j)
- printf(4d,ai j)
- printf(\n)
?? ?????? ??? ?????? (?????????) ????? ??????.?
?? ???????. ?? ?? ???? ???? ?????.
4??????? ??????
- ?????? ??? ??? ????? ??? ?????? (???? ???? ??
????). - ??? ????? ?????? ??????? ????? ?? ?????, ??????
???? ??????? ???? ?? ??-????? \0, ????? ????
??? ???????. - ???? ????? ?????? ?????? char message Hello
world! - ???? ???? ???/??? ?? ??????? ??-?? ??????, ??
???-??? - scanf(s, str), scanf(40s, str),
gets(str), printf(s,str) - ?????? string.h ?? ?????? ???????? ?? ???????
(??? ?? ????, ??-???? ????? ab ??? ??????
??????? ?? ab ??? ??????).
5string.h ??????? ????????
- ????? ???? ??????? (??? ????? ?? ??-????? '0\')
- len strlen(my_string)
- ?????? ??????? (?? ?? ???? ????? 0)
- equal strcmp(str1, str2)
- ????? ?????? ??????? ???? (source ??????
?-target) - strcpy(target, source)
- ?????? ??????? (????? ?? str2 ???? str1)
- strcat(str1, str2)
- (????????? ????? ?????? ?? ????? ?? ????? ???????
?????).
6????? ??????-?? ???????
- ?? ???? ?????? ?????? ???? ??? ?????. ???? a
?? ? - ?????? ????? ??????? ?????? ???? ?????? ??????.
???? HELLO - ?? ?????? a ?? ??????? ??? ?????? ??? ?? ?? ???
a ?????? ?? ??? \0. ????? ?? ???? ???? ?????
a. - ?? ??????? ?????? ?? ??????? ???? ?????? ??
?????? ??????, ???? - strcmp(input,a)
- ???
- strcmp(input,a)
a'0\'
7????? ?? ???? ??????? ?????
- includeltstdio.hgt
- includeltstring.hgt
- int main()
-
- int bush_votes 0 , kerry_votes0
- char vote6
- while(1)
-
- scanf(5s, vote)
- if (strcmp(vote, Bush)0)
bush_votes - else if (strcmp(vote, Kerry)0)
kerry_votes - else if (strcmp(vote, Stop)0)
break - else printf(Wrong vote!\n)
-
- printf(Bush received d votes and Kerry
received d - votes\n, bush_votes,
kerry_votes)
8????? ?? ???? ??????? ?????
- includeltstdio.hgt
- includeltstring.hgt
- int main()
-
- int bush_votes 0 , kerry_votes0
- char vote6
- while(1)
-
- scanf(5s, vote)
- if (strcmp(vote, Bush)0)
bush_votes - else if (strcmp(vote, Kerry)0)
kerry_votes - else if (strcmp(vote, Stop)0)
break - else printf(Wrong vote!\n)
-
- printf(Bush received d votes and Kerry
received d - votes\n, bush_votes,
kerry_votes)
????? ?????? ???? ?????, ?? ??????? ?? ?????
?????? ?????? ??????
break?????? ????? ?? ???? ?"?
????? ?????? ????? 5 ??? ?????
?????? ???? ?????? ?????
9????? ?? ???? ??????? ?????
???, ????????? ?????-?????? ????????? ?? ??????
????? ??????.? ???????.
- includeltstdio.hgt
- includeltstring.hgt
- int main()
- int a0,b0
- char c6
- while(1) scanf(5s,c)
- if (strcmp(c,Bush)0) a
- else if (strcmp(c,Kerry)0) b
- else if (strcmp(c,Stop)0) break
- else printf(Wrong vote!\n)
- printf(Bush received d and Kerry received
d\n, a, b)
10??????? ????? ??????-??
- ????????? ??????? ??? ?"? ????? ?? ?????? ????,
?? ??-????? '0\' ????? ???????? ???? ???? ???????
(??? ??????? ???? ??????). ???? - char str Hello
- scanf(s, str) scanf(40s, str) gets(str)
- ?? ??????? ??????? ??-??, ?? ?"? ????? ?? ??????
????, ?? ???? ?????? ?????? ?? ??-????? ??? ?????
????-??? ?????? ?? ??????? ???????. ???? - char str H,e,l,l,o,\0
11??????? ??? ????? ??????-??
- ????? ??- Enter ?????? ????? ???? ????
???????-???? ?? ?????. ????? ?? ????? ?? ????
?????? ?????? ?? ??? ???? ?? \n (??? ?????
????? ?? ????) - scanf(s, str)
abcd - scanf(c, tav)
- ??? ?????? ????, ???? ?????? ?? ?? ?"? ?? ?????
??????-???? ???? ???? ?? \n - scanf(s, str)
abcd - scanf(\nc, tav) e
12????? ???????
13????? ?????? ???? ?????? ????????
- ??? ?????? ???????
- ?????? ?? ??????
- ??? ??????? ??? ???? ????? ????
14?????? ???????
- ????? ???? ???????? ?? ????? ????? ????? (????)
????. ??????? ???????? ????? ????????? ??????
?????????. - ??? ?? ??????? ?? ????? (???? ??).
- ?? ????? ???? ??????? ??? ?????? ??????? (???
???? ????? ???? ??? ???, ????? ?????? ??????). - ????, ????????? ????? ??-???
int i - ????? ???? ???? ?????? i ???? ??????? ??????
???? ????. ??? ???? ???? ?? ?????? ???????.
15?????? ??????? - ?????
???????
???????
???? ???????
?????
?????
?
i 7500
7500
????? ????? ?????? ???
????? ????? ?????? ???
16?????? ??????? - ?????
???????
???????
???? ???????
?????
?????
10
i 7500
7500
??? ?????? ?????? ???????
17?????? ??????? - ?????
???????
???????
???? ???????
?????
?????
10
i 7500
7500
???? ??? ?? ???? ???? ???????
18?????? ??????? - ?????
???????
???????
???? ???????
- int main()
-
- int i10
- char cA
10
?????
?????
7500
i 7500 c 9200
A
9200
?? ?? ???? ?????? ?????? ?????
19?????? ??????? - ?????
???????
???????
???? ???????
- int main()
-
- int i10
- char cA
10
?????
?????
7500
i 7500 c 9200
65
9200
?????, ????? ???? ??? ????? ?? ???
20?????? ??????? ???? ??????
- ????? ??????? ???? ???? ????, ???? ???? ?????
(????) ??????? ????? ?????? ???. - ????, char ????? ??-??? ??? ???, int ??-???
?????, ????? double ????? (???? ???????????). - ??????? ???????? ??????? ??? ?? ?????, ????? ????
????? ???? ?????? ??? ???? ??????? ???? ???? ???
????, ??? ??? ???? ????? ??? ?? ???? ???.
21?????? ??????? - ?????
???????
???????
???? ???????
- int main()
-
- int i10
- char cA
?????
?????
????
0
0
0
10
i 7500 4 c 92001
7500
65
9200
????? ???? 4 ???? (????). int???? ?? ????? ???
?? ?????? ???????? ???? ???????.
22?????? ???????
- ?? ????? ???? ?????? ??????? ???????
- ?? ???? ?? ?????? ??????? ???????
- ??????
23?????? ??? ???????? ?????
- ??? C ?????? ??? ???? ??? ?????? ??????? ??? ????
????? ??????. - ?????? ????? ?? ?????? ?? ??????.
- ???? i ??? ?????? ??????? ?? ?????? i.
- ?????? ?????? i ???? 7500.
24?????? ??????? - ?????
???????
???????
???? ???????
?????
?????
????
10
i 7500 4
7500
i ?? 7500
25?????? ??? ?????? ?????
- ????? ??????? ????? ?? ?????? ?? ?????.
- ???? i ??? ?????? ??????? ?? ?????? i.
- ?????? ?????? i ??? ???? 7500.
- ?????? ????? ???? ????? ?????? ???????.
- ???? (4000) ?? ???? ????? ?????? 0040.
- (c) ?? ???? ?? ?????? c (?? ?? ???? ?????
?????? ??(c .
26?????? ??????? - ?????
???????
???????
???? ???????
?????
?????
65
c 9200
9200
(9200) ?? 65
27?????? ?? ???? ????? ????
- ?? ???? ????? ????? ?? ?????.
- ????? ?? ???? ????? ???? i5000.
- ???? ????? ?? ???? ????? ?????? ???????.
- ???? (c)A.
- ?? ??? ????? cA.
- ????? ????? ?? ???? ????? ?????? ????? ??????
????? ?? ?????. ???? (4000)123. - ????? ?????? ????? ???? ??????? ????? ??????
??????, ?????? ??????? ????. - ??? ???? ?? ????? ?? ?????? ???????.
28????? ?? ?? ?? ????
- ??? ??? ????? ??? ?? ????? ???? ???? ???? ?? ???.
???? i10. ?? ????? ?? ????? ???? ?? ?????? ???? - ??? ?????? ???? ??? ?????? ??????? ??? ??????
???? ??? ???????
29????? ?? ????? ???????
- ????? ??? ????? ???? ?? ???? ???????? ???? ?????
??. - ????? ??????? ??? ????? ??? ?? ????? ???? ???????
????, ???? ?? ????? ??. - ????, ?? ????? ???????? ???? ??? ?????? (??? ??
????? ??? ???), ?? ???? ?????? ???? ?? ???????
????. ?? ????? ?? ????? ????? ???? ?? ??????
???????.
30????? ??????
- ??????? ?????? ????? ???????? scanf, ?????? ??
????? ?????? ????? ????? ????. ???? - int grade
- scanf(d, grade)
- ?????? grade ?? ????? ???????? scanf ???? ?? ??
?????? ????? ???. - ???????? scanf ????? ?? ?????? ?? ?????? ???????,
??? ????? ?? ????? ????? ?? ???? (????? ??????
?????? ????). - ????? ???? (???? d) ???? ?- scanf ?? ?? ????
?????? ??? ???????, ????? ???? ???? ???? ????
??????.
31?????? ??????? - ??????
- ????? ?????? ?? ????? ?? ??????
- ???? ???? ?? ????? ??? ?????? ?? ??????
- ?? ????? ??? ????? ???? ?????? ??? ????????
- ??????
32????? ?? ?????? - ???????
- ?? ?-C ??????-?????? ?????? ?????? ???????.
- ?? ?????? "???????" ?? "?????????".
- ???? ?????? ????
- char my_pointer
- int pointer1
- ????? ????, ??? ?????? ????? ???? ?????, ??????
?? ??? ?????? ????? ???????, ??????? ???? ??
??????. - ??? ??????? double my_pointer1 float
ptr
char ????? ?????? ????? ?? int ????? ??????
????? ??
33????? ?? ?????? - ???????
- ?? ?-C ??????-?????? ?????? ?????? ???????.
- ?? ?????? "???????" ?? "?????????".
- ???? ?????? ????
- char my_pointer
- int pointer1
- ????? ????, ??? ?????? ????? ???? ?????, ??????
?? ??? ?????? ????? ???????, ??????? ???? ??
??????. - ???? ?? ??? ????? ??? ??????? (?????? ?????
?????? ?????), ???? ?????? ?????? ???? (?????
???? ??????).
char ????? ?????? ????? ?? int ????? ??????
????? ??
34??????? ??????
- ????? ???? ????? ????? ("??") ?????? ???. ??????
- int i10
- int my_pointer
- my_pointer i
int ????? ????? ?????? ????? ??
i?????? ???? ?????? ??????? ?? ??????
35???? ?????? ??-??? ?????
- ?????, ??? ??????? ???? ????? ?????? ???????,
??????? ????? . ????? ??? ?????? ?????? ?? ?? - int i10
- int my_pointer
- my_pointer i
- my_pointer 100
- printf(The value of i is now d, i)
int????? ????? ??
i???? ?????? ?? ????? ??????
???? 100 ????? ????????? ????? ????
????? ????? 100
36??? ?? ????? ???? ??? ??????
- ??? ?????? ???? ?? ???? ?????? ???????? ????,
???? ????? ??????? ????? ?????? ???? (???? ??? ??
????). - ?? ?????????? ???? ????? ???????, ????? ???? ????
???? ??? ????? ????, ?????/????? ?? ???? ?????. - ????? ????? ??? ?? ????? ?? ?????
"??????-??????". - ?? ????? ???? ?- int ????? ??????? ???? ???? i,
?? ???? ?????? 1 ?????? ?? i, ?????? ??? ????
???? ?????? ????? ????? ?? int
37??????? ??????? ?????? ??????-??
- ???? ?? ???????? ???????? ??? ?????. ????, ??
????? - 5
- (i2)
- ?? ??????? ?? ?????.
- ????? ??? ???? ????? ????? ?? ????? (????? ????
????), ?? ???? ???? ???? ???? ab.
38??????? ????? ??????
- ??? ?????? ??????? ?????? ????? ?? ????? ???.
- ??? ?????? ???? ?????? ?"? ??? ?????? ????????
???? ?- . ???? int my_ptr - ???? ???? ???? ?????? ????????? ????? ???? ?????
. ???? my_ptr5 - ??????
39??????? ?????
- ???? ??????? ?????? ?????? ?? ??? ?????? ????
int, ??????? ??? ?????? ????. - (?? ????? ?? ?????? ????? ??????? ?????? ????? ??
??? ?????? ???? int, ?? ????? ?????? ???? int
???????? ?? ????? ?? ???? ??????, ???????? ?????
?????? ?? ??? ???). - void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- ?????? ???? ??-??? swap(i, j)
first ??? ?????? ??????? ?????? ?? ????? ?? ???
?????? ??????? ?????? ?? second
40????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
41????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
42????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
10
i
20
j
43????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
first
second
10
i
20
j
44????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
first
second
temp
10
i
20
j
45????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
first
second
temp
10
10
i
20
j
46????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
first
second
temp
10
20
i
20
j
47????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
first
second
temp
10
20
i
10
j
48????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
20
i
10
j
49????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
??? ??????? ?? ?????? ????? ???? ?????? ???
??-??? ???????
20
i
10
j
50- ?????? ???? ??
- ?????? ???????
- ???????
- ????? ?????? ?????? ????????
-
51????? ???????
52?????? ?