i int int i - PowerPoint PPT Presentation

1 / 48
About This Presentation
Title:

i int int i

Description:

????? ????? 14. ????: 2.2.06. ??? ?????? ??????-??. ??? ???? ... float im; /* The imaginary part. */ typedef struct _Complex Complex; ???-?? ????? ??? ????????: ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 49
Provided by: csta3
Category:
Tags: an | imaginary | in | int

less

Transcript and Presenter's Notes

Title: i int int i


1
????? ????? 14
  • ????
  • 2.2.06

2
??? ?????? ??????-??
  • ??? ???? ?????? ?? ????? (???? ???????).
  • ?? ????? i int ??? int i
  • ?? ?????? ??????? ?"?int f() int n ??? int f(int
    n)
  • ???? ?????? ??????? ??????? ??????? ???? ??
    ?????? ?????.
  • ??? ?????? ?????? ???? ???? ????? ?-"???????"
    ????? ????? (???? ??????? ????? ?????? ???).
  • ???? ????-?? ????? ?? ?????, ??????, ????? ?????.

3
????? ????? ?????
  • ?????? ???????, ???/??? ??????? ?????
  • ????? if ?- switch ??????? ??????
  • ?????? while, for, do while
  • ????????
  • ??????
  • ???????
  • ???????
  • ???????
  • ?????
  • ????? ?????? ???????
  • ?????? ???????
  • ?????

4
???? 1 ????? ????? ???"?
  • ???? ??' 1 (25 ??????)
  • ???? ??????? ???????? ?? ????? ??? ???????? ?????
    (structure) ?????? ????? ???
  • struct _Complex
  • float re / The real part. /
  • float im / The imaginary part. /
  • typedef struct _Complex Complex
  • ???-?? ????? ??? ????????
  • void complex_set (Complex p_z, float x,
    float y)
  • p_z-gtre x
  • p_z-gtim y
  • return

5
???? 1 ????? ????? ???"?
  • ????? ??? ?????? ????
  • int main ()
  • Complex p_z
  • complex_set (p_z, 3, 4)
  • / The rest of the program comes here ... /
  •  
  • return (0)
  •  
  •  
  • ?????? "???" ???? ?????. ?? ????? ?????? ??????
    ?"?????"?

6
???? 1 ????? ????? ???"?
  • void complex_set (Complex p_z, float x, float y)
  • p_z-gtre x
  • p_z-gtim y
  • return
  • ???? ?' (5 ??????) ????? ??? ?????? ????
  • int main ()
  • Complex p_z
  • complex_set (p_z, 3, 4)
  • / The rest of the program comes here ... /
  •  
  • return (0)
  • ?????? "???" ???? ?????. ?? ????? ?????? ??????
    ?"?????"?

7
???? 1 ????? ????? ???"?
  • void complex_set (Complex p_z, float x, float y)
  • p_z-gtre x
  • p_z-gtim y
  • return
  • ???? ?' (5 ??????) ????? ??? ?????? ????
  • int main ()
  • Complex p_z
  • complex_set (p_z, 3, 4)
  • / The rest of the program comes here ... /
  •  
  • return (0)
  • ?????? "???" ???? ?????. ?? ????? ?????? ??????
    ?"?????"?

8
???? 1 ????? ????? ???"?
  • void complex_set (Complex p_z, float x, float y)
  • p_z-gtre x
  • p_z-gtim y
  • return
  • ???? ?' (5 ??????) ????? ??? ?????? ????
  • int main ()
  • Complex p_z
  • complex_set (p_z, 3, 4)
  • / The rest of the program comes here ... /
  •  
  • return (0)
  • ?????? "???" ???? ?????. ?? ????? ?????? ??????
    ?"?????"?

?????? ????? ?- p_z ????? ???? ??? ????? ?? p_z
9
  • ???? ?' (5 ??????) ????? ??? ????? ????
  • int main ()
  • int n
  • Complex values
  • int i
  • / Read the number from the user /
  • printf (Please enter the number of values )
  • scanf (d, n)
  • / Allocate memory /
  • values (Complex ) malloc (8 n) 
  • / Initially set all complex values to be 0. /
  • for (i 0 i lt n i)
  • complex_set (values i, 0, 0)
  • / The rest of the program comes here ... /
  • free (values)
  • return (0)

10
???? 1? ????? ????? ???"?
  • ?????? ?????? ?????, ?? ???? ??????? ????? ??
    ????? ????? ????, ??-??? ??????? ???? ????? ????
    ????, ?? ???? ???? ?????
  • Struct _Complex
  • double re / The real part. /
  • double im / The imaginary part. /
  • Complex
  • typedef struct _Complex Complex
  •  
  • ?? ???? ?????? ??? ???? ???? ?? ?- main ??? ???
    ???? ????? ????
  •  

11
???? 1? ????? ????? ???"?
????
struct _Complex float re / The real part.
/ float im / The imaginary part.
/ typedef struct _Complex Complex
  • struct _Complex
  • double re / The real part. /
  • double im / The imaginary part. /
  • Complex
  • typedef struct _Complex Complex
  •  
  •  

?????
12
  • ???? ?' (5 ??????) ?? ????? ???? ???? ?????
  • int main ()
  • int n
  • Complex values
  • int i
  • / Read the number from the user /
  • printf (Please enter the number of values
    \n)
  • scanf (d, n)
  • / Allocate memory /
  • values (Complex ) malloc (8 n) 
  • / Initially set all complex values to be 0. /
  • for (i 0 i lt n i)
  • complex_set (values i, 0, 0)
  • / The rest of the program comes here ... /
  • free (values)
  • return (0)

13
  • ???? ?' (5 ??????) ?? ????? ???? ???? ?????
  • int main ()
  • int n
  • Complex values
  • int i
  • / Read the number from the user /
  • printf (Please enter the number of values )
  • scanf (d, n)
  • / Allocate memory /
  • values (Complex ) malloc (8 n) 
  • / Initially set all complex values to be 0. /
  • for (i 0 i lt n i)
  • complex_set (values i, 0, 0)
  • / The rest of the program comes here ... /
  • free (values)
  • return (0)

?? ???? ?????, ?????? ????? ????? ??? float, ???
??? ?? ????? ???? double.
14
  • ???? ?' (5 ??????) ?? ????? ???? ???? ?????
  • int main ()
  • int n
  • Complex values
  • int i
  • / Read the number from the user /
  • printf (Please enter the number of values )
  • scanf (d, n)
  • / Allocate memory /
  • values (Complex ) malloc (sizeof(Complex)
    n) 
  • / Initially set all complex values to be 0. /
  • for (i 0 i lt n i)
  • complex_set (values i, 0, 0)
  • / The rest of the program comes here ... /
  • free (values)
  • return (0)

????? ????? ?? ?????
15
???? 1 ????? ????? ???"?
  • ???? ?' (5 ??????)
  • ?? ???? ???????? ????
  • void secret (const char s1, char s2)
  • while (s1)
  • s2 s1
  • s1
  • s2
  • s2 s1

16
???? 1 ????? ????? ???"?
  • ???? ?' (5 ??????)
  • ?? ???? ???????? ????
  • void secret (const char s1, char s2)
  • while (s1)
  • s2 s1
  • s1
  • s2
  • s2 s1

????? ??????? ???? ??????? ??????? ?? ??????? s1
??????? s2.
17
???? 1 ????? ????? ???"?
  • ???? ?' (5 ??????)
  • ?? ???? ???????? ????
  • void secret (const char s1, char s2)
  • while (s1)
  • s2 s1
  • s1
  • s2
  • s2 s1

?? ??? ??? ?????? ?- s1 ???? 0, ????? ?? ?????
???? s1 ('0\')
18
???? 1 ????? ????? ???"?
  • ???? ?' (5 ??????)
  • ?? ???? ???????? ????
  • void secret (const char s1, char s2)
  • while (s1)
  • s2 s1
  • s1
  • s2
  • s2 s1

?? ??? ??? ?????? ?- s1 ???? 0, ????? ?? ?????
???? s1 ('0\')
??????? ???? ????? ?????? ?- s2
19
???? 1 ????? ????? ???"?
  • ???? ?' (5 ??????)
  • ?? ???? ???????? ????
  • void secret (const char s1, char s2)
  • while (s1)
  • s2 s1
  • s1
  • s2
  • s2 s1

?? ??? ??? ?????? ?- s1 ???? 0, ????? ?? ?????
???? s1 ('0\')
??????? ???? ????? ?????? ?- s2
???????? ???? ????????
20
???? 1 ????? ????? ???"?
  • ???? ?' (5 ??????)
  • ?? ???? ???????? ????
  • void secret (const char s1, char s2)
  • while (s1)
  • s2 s1
  • s1
  • s2
  • s2 s1

?? ??? ??? ?????? ?- s1 ???? 0, ????? ?? ?????
???? s1 ('0\')
??????? ???? ????? ?????? ?- s2
???????? ???? ????????
???? ??? ?????? ??????? ?- s2 ???? ?? ?- '\0'
???? ???? s1
21
???? 1 ????? ????? ???"?
  • ???? ?' (5 ??????)
  • ?? ???? ???????? ????
  • void secret (const char s1, char s2)
  • while (s1)
  • s2 s1
  • s1
  • s2
  • s2 s1
  • s1 ???? ?????? ?? s2????????? ????? ????? ??????
    ?????? ? s2

22
  • ???? ?' (5 ??????)
  • ????? ??? ?????? ????, ?????? ????? ??????
    ?? ?????? ?? ??? ?? ?? ??????? ???? ?? Enter ???
    ????? ???? ??????? ?- 80 ????? ??? ?????, ???
    ?????? ?? ??????? ?? ????.
  • define MAX_STR 80
  • int main ()
  • char str MAX_STR 1 / The string. /
  • int l_str 0 / Its length. /
  • int c
  • while ((c getchar()) ! \n)
  • if (l_str MAX_STR)
  • printf (Error too long.\n)
  • return (1)
  • strl_str c
  • l_str
  •  
  • printf (s\n, str)

23
  • ???? ?' (5 ??????)
  • ????? ??? ?????? ????, ?????? ????? ??????
    ?? ?????? ?? ??? ?? ?? ??????? ???? ?? Enter ???
    ????? ???? ??????? ?- 80 ????? ??? ?????, ???
    ?????? ?? ??????? ?? ????.
  • define MAX_STR 80
  • int main ()
  • char str MAX_STR 1 / The string. /
  • int l_str 0 / Its length. /
  • int c
  • while ((c getchar()) ! \n)
  • if (l_str MAX_STR)
  • printf (Error too long.\n)
  • return (1)
  • strl_str c
  • l_str
  •  
  • printf (s\n, str)

?? ??? 0\ ???? ???????, ???? ?????? ?? ????? ???
???? ??????? ???????, ?? ????? ????? ??? 0\.
24
  • ???? ?' (5 ??????)
  • ????? ??? ?????? ????, ?????? ????? ??????
    ?? ?????? ?? ??? ?? ?? ??????? ???? ?? Enter ???
    ????? ???? ??????? ?- 80 ????? ??? ?????, ???
    ?????? ?? ??????? ?? ????.
  • define MAX_STR 80
  • int main ()
  • char str MAX_STR 1 / The string. /
  • int l_str 0 / Its length. /
  • int c
  • while ((c getchar()) ! \n)
  • if (l_str MAX_STR)
  • printf (Error too long.\n)
  • return (1)
  • strl_str c
  • l_str
  •  
  • strl_str\0

25
  • ???? ?' (5 ??????)
  • ?? ???? ???????? ????

void my_func (double vec, int n) double
min_val int i_min, i if (n 1)
return min_val vec0 i_min 0 for (i
1 i lt n i) if (veci lt
min_val) min_val veci i_min i
veci_min vec0
vec0 min_val  my_func (vec 1, n
1) return
26
  • ???? ?' (5 ??????)
  • ?? ???? ???????? ????

void my_func (double vec, int n) double
min_val int i_min, i if (n 1)
return min_val vec0 i_min 0 for (i
1 i lt n i) if (veci lt
min_val) min_val veci i_min i
veci_min vec0
vec0 min_val  my_func (vec 1, n
1) return
??? ??? ?????? ?? ????? ???????? ?????, ????????
???? ????? ??????, ??? ??????? ?? ??????? ???????
????? ???? ????? (?? ????? ?? ???? ???).
27
???? 2 ????? ????? ???"?
  • ???? ?' (12 ??????)
  • ???? ??????? ???? ????? ???
  • int convert (const char s, int p_value)
  • ???????? ????? ?? ???? ?????? ??????? ?????? ????
    s ??????? ???? ??? ?????? ?- p_value ?????
    ????.
  • ?? ???????? ?????? 1 ????? ??????? ???? ??????
    ???? ??? (???? 1634 ?? -834 ) ?- 0 ??? ????
    ??? (???? ab23jd ?? 14.67).

28
  • int convert (const char s, int p_value)
  • int sign 1
  • int num 0
  • int i 0
  • / Save sign, if necessary /
  • if (si '-')
  • sign -1
  • i
  • if (si \0)
  • return 0
  • / Read digits and add to num /
  • while (si ! '\0')
  • if ((si lt '0') si gt '9' )

29
???? 2 ????? ????? ???"?
  • ???? ?' (13 ??????)
  • ???? ??????? ???? ????? ???
  • int calc_sum (const char strs, int n)
  • ???????? ????? ???? ?? ??????? ??????? ?? ????
    ?????? ?? ??????? ??? ???????

30
  • int calc_sum (const char strs, int n)
  • int i 0
  • int sum 0
  • int num 0
  • for (i 0 i lt n i)
  • if (convert(strsi, num))
  • sum num
  • return sum

31
???? 3 ????? ????? ???"?
  • ???? ?' (5 ??????) ???? ???? ?????? ????? ??????
    ????? ?????? ????.

32
  • typedef struct Point_t
  • double x
  • double y
  • Point
  • typedef struct Circle_t
  • Point p
  • double r
  • Circle

33
???? 3 ????? ????? ???"?
  • ???? ?' (10 ??????) ???? ??????? ???? ????? ???
  • int is_in_circle(const Circle c,const Point p)
  • ???????? ?????? 1 ?? ?????? p ????? ???? ????? c
    ?- 0 ?? ??? ???? ????? ??.

34
  • double distance(Point p1, Point p2)
  • return sqrt(pow(p1.x - p2.x, 2)pow(p1.y - p2.y,
    2))
  • int is_in_circle (const Circle c, const Point
    p)
  • return ( distance(p,c-gtp) lt c-gtr )

35
???? 3 ????? ????? ???"?
  • ???? ?' (10 ??????) ???? ?? ??????? ????
  • ????? ?? ?????? ???? ??? n.
  • ????? ?? ?????? n ??????, ???? ??? ?????? ?????
    ?????? ????? ??????.
  • ?????? ????? ?? ?????? ?????
  • ??????? ????? ??? ?????? ?????? ?? ?????? ???????
    ???? ?? ????.

36
  • int main()
  • int n, i
  • Circle Circles
  • Point p
  • int number_circles0
  • printf("How many circles would you like to
    enter?\n")
  • scanf("d", n)
  • / Allocate memory to hold this many circless /
  • Circles (Circle )malloc(sizeof(Circle)n)
  • if (CirclesNULL)
  • printf("Memory allocation failed!\n")
  • return 1
  • for(i0 iltn i)

37
  • / Go over all the circles and for each circle
    check whether it contains the point /
  • for(i0 iltn i)
  • if (is_in_circle(Circlesi,p))
  • number_circles
  • / Print number of circles containing the point
    /
  • printf("Number of circles containing the point
    is d\n", number_circles)
  • / Free the allocated memory /
  • free(Circles)
  • return 0

38
???? 5 ????? ???? ????? ???"?
  • ???? 5 (25 ??????)
  • ???? ?' (5 ??????)
  • ?????? ???? (structure) ??? ???? ?????? ?????
    ?????? ??? ???? ?????? ????? (??? ?????).

39
???? 5 ????? ????? ???"?
  • ???? ?' (5 ??????)
  • ?????? ???? (structure) ??? ???? ?????? ?????
    ?????? ??? ???? ?????? ????? (??? ?????).
  • ?????
  • struct item
  • int data
  • struct item next

40
???? 5 ????? ????? ???"?
  • ???? ?' (5 ??????)
  • ?????? ???? (structure) ??? ???? ?????? ?????
    ?????? ??? ???? ?????? ????? (??? ?????).
  • ????? ?? ???? ?????
  • struct item_t
  • int data
  • struct item_t next
  • typedef struct item_t item

41
???? 5 ????? ????? ???"?
  • ???? ?' (10 ??????)
  • ???? ??????? ?????? ????? ???? ?????? ???????
    ?? ???? ??????? ??????.

42
???? 5 ????? ????? ???"?
  • ???? ?' (10 ??????)
  • ???? ??????? ?????? ????? ???? ?????? ???????
    ?? ???? ??????? ??????.
  • ?????
  • int sum_list(item list)
  • int sum0
  • while (list ! NULL)
  • sumsumlist-gtdata
  • listlist-gtnext
  • return sum

??????? ?? ????? ?????? ??????? ?? ?????? ???????
???
43
???? 5 ????? ????? ???"?
  • ???? ?' (10 ??????)
  • ???? ??????? ??? ???? ????? ???? ??????, ???
    ????? ?? ?????? ?????? ????? ?????? ??????
    ????????.

44
???? 5 ????? ????? ???"?
  • ???? ?' (10 ??????)
  • ???? ??????? ??? ???? ????? ???? ??????, ???
    ????? ?? ?????? ?????? ????? ?????? ??????
    ????????.
  • ???? ??????
  • ????? ?? ?????? ??????? ?? ????? ?- NULL.
  • ??? ??? ????? ?? ????? ??????, ?????? ???? ????
    ?????? ????? (?? ??? ????? ?????? ?????? ????? ??
    ?? ???? ??? ??????).
  • ?????? ?????? ????? ????? ???? (new_item), ?????
    ???? ?????? ????? (new_head), ????? ????? ??????
    ??????? ?????? ????? (new_last).

45
  • ????? ???? ?' (10 ??????) ????? ?????
  • item duplicate(item head)
  • item new_item, new_lastNULL,
    new_headNULL
  • while (head ! NULL)
  • new_item(item ) malloc(sizeof(item))
  • new_item-gtdatahead-gtdata
  • new_item-gtnextNULL
  • if (new_head NULL)
  • new_headnew_item
  • else
  • new_last-gtnextnew_item
  • new_lastnew_item
  • headhead-gtnext
  • return new_head

??????? ?? ?????? ???????
????? ?????
?? ??? ????? ?????? ?????? ?????, ?? ?? ???
??????
???? ?????? ????? ????
?????? ??????? ???? ??????
??????? ?? ??? ?????? ?????
46
????? ?????? ??
  • ????? ???????? ??????? ????? ???? ??????, ??????
    ???? (?????? ???? ??????).
  • sum_list(item list), duplicate(item head)
  • ???? ?? ??? ?? ???? ?? ?????? ???? ?????? ???????
    ?????? (?? ????? ????? ????? ????????). ????
  • sum_list(list_head1)
  • ???????? ?????? ?????? ?????? ?????? ???, ??? ??
    ?????? ?? ??????. ??? ???? ?????? list_head1 ??
    ????? ?????? ??????? ????????.
  • ???? ????? ???????? ?? ?????? ???? (?? ?????? ??
    ??????).

47
???? 5 ????? ????? ???"?
  • int sum_list(item list)
  • int sum0
  • while (list ! NULL)
  • sumsumlist-gtdata
  • listlist-gtnext
  • return sum

?? ???? ?????? ?????
sum_list(head)
?????? head ?? ?????, ?? ?? ?????? ???????? ?? ??
?????? ?????? ??. ???? ????? ?? list ????????,
??? ????? ?- head.
48
????? ?
Write a Comment
User Comments (0)
About PowerShow.com