.


:




:

































 

 

 

 


- "" , . , . , "x". ----- / x / --------------- | | | , | | 12 | --------------- . . x = 12; " 12", " 12", " 12". , . . x = x + 3; . , . : 1) " " 2) " 3" 3) " ", . : . _ = _; . , " ". , . , " " ! , . : x = x + 3; x 12 . x + 3 ----- / x / --------------- | 12 | | --------|------ | | | ( 12) "" | V x 12 + 3 ----> . 15. x 12 ( 12) : x = 15; | | | "" | ( , ) -----| / x / | --------|------ | 12 V | --------------- : ----- / x / --------------- | 15 | --------------- , . "". , Pascal Modula, := = , = . . : z = x * x + 2 * x; : z - . x - - . x * x " " ( , !) x * 2 " " + . . , , , , : = 1; = 1; "" "", . . , . , (..., -2, -1, 0, 1, 2, 3,...), : int 1; int 2; : int 1, 2; int integer - "".

, . , . /* */ int x, y; /* 0 */ /* , 2 */ /* - . */ /* */ x = 3; /* 1 */ y = 4; /* 2 */ x = x + y; /* 3 */ y = y - 1; /* 4 */ x = y; /* 5 */ (, ) : x y/* 0 */ /* 1 */ 3 /* 2 */ 3 4/* 3 */ 7 4/* 4 */ 7 3/* 5 */ 3 3 , , , . x = y; x y . , " " . , x y , . ----- ----- / x / / y / --------------- --------------- | 3 *<--|--------<----|-- 3 | --------------- 1) --------------- 2), 3) 4) 1) y 3 ( ).2) x .3) 3 x.4) y 3. : printf("%d\n", x); "". : x + y x - y x * y x / y ( ; - ) x % y 5 / 2 2 5 % 2 1 : x = x + 1; " 1" x++; ( ++x;)x = x - 1; " 1" x--; ( --x;)x = x + y; " y" x += y;x = x * y; " y" x *= y;x = x / y; " y" x /= y; x++; x += 1;

* *

, , . 1; | 2; | 3; | 4; V

if() ;...... : . , , . , , . , {... } - " ". if() { 1; 2;... } } ( , ). : | | | ---------------- ---| |---- | ---------------- | | | V V | | V |------------ || | |------------ | | | ------->-------<------- | | V | , "": if() __; else __; " , " ( ) | | | ---------------- ---| |----------- | ---------------- | | | V V | | V |------------------------- -----------------------| __ | | __ |------------------------- ----------------------- | | ------->-------<-------------- | | V | 1: if(x > 10) printf(" \n"); 2: int x, y, z; if(x < y) z = 1; else z = 2; : ( , , ) x < y x > y x <= y x >= y x == y x!= y 1, 0, . , : if().... - . ... -2, -1, 1, 2, 3,... - . . , : if(x!= 0)...; if(x)...;if(x == 0)...; if(!x)...;-------------------------------------------------------------------------: int x, y, z; if(x == 1){ y = 2; z = x + y; } else { y = 1; z = x - y; } ------------------------------------------------------------------------- : if(x == 1){ printf(" 1\n"); if(y == 2){ printf(" 2\n"); } } else { printf(" 1\n"); }------------------------------------------------------------------------- , : if(x == 1) printf(" 1\n"); else if(x == 2) printf(" 2\n"); else if(x == 3){ printf(" 3\n"); y = 1; } else printf(" \n");------------------------------------------------------------------------- - , ==, = = " ", " ".

while (" , ")

while() ;...... while(){ ;... }...... | V | +------>--+ | | | V | --------------------- | | |-------> () A --------------------- | | | | | V | | ( ) | | | | | V | | V | | | | | | +-----<---+ | | +-------<---------------------+ | V : int x; x = 10; while(x > 0){ printf("x=%d\n", x); x = x - 1; } printf(".\n"); printf("x %d.\n", x); /* 0 */ "" , . , - - , .

", , "

. < 10 ...; ...; ...; : if(1 && 2)...; /* "" */ if(1 || 2)...; /* "" */ if(! 1)...; /* "" */ : if(4 < x && x <= 12)...; if(4 < x <= 12)...; ! : if(x < 3 || y > 4)...; if(! (x < 3 || y > 4))...;

for (" ")

while. , " ", " N-". " " " ". int i; i = a; /* */ while(i < b){ _; i += c; /* */ }...... int i; for(i=a; i < b; i += c) _; _ i a a+c a+c+c... i < b for(i=1; i <= N; i++) printf("i=%d\n", i); i " ". .

break (" ")

break . while(1){ 1; if(2) break; ------->----+ | 2; | } |......<--------<---------+ for(i=0; 1; i++){ 1; if(2) break; ------->----+ | 2; | } |......<--------<---------+ ( ). : for(i=0; i < 20; i++){ printf("i=%d\n", i); if(i == 7){ printf("break loop!\n"); break; /* */ } printf("more\n"); } printf("finished, i=%d\n", i); /* 7 */ , : for(;;){ /* */ 1; if(2) break; ------->----+ | 2; | } |......<--------<---------+ , . . - break ( - ) , . while(1){... }

()

printf(""); . printf("\n"); . printf("1 2 "); printf("3\n"); 1 2 3 . , \n, . printf("%d", x); x. %d " ". printf(" %d - -\n", x); x , - - ( \n). : int x, y; x = 12; y = 15; printf(" %d, %d, .\n", x, y); ~~~~~~ . " %d, %d\n" . , %d. _ _ ~~~~ . 12_ %d 12, _ : 12, 15_ , \n. , printf . 12, 15, . _ , : printf(": %d\n", 12 + 3 * 5); , : int x, y, z; x = 13; y = 23; z = 34; printf("x=%d xx=%d\nzzz=%d\n", x, y - 1, z * 2 + 1); , : x=13 xx=22 zzz=69 _ , , . printf("x=%d\n y=%d\n", x, y); x=13 y=23_ y , \n!!! .

, , ( ). , . - , - . - , . . : int func(int x){ /* , return(); */ return x+1; } ------------------------------------------------------------------------- int func(... func( , ). int , .-------------------------------------------------------------------------...(int x)... ( ) .-------------------------------------------------------------------------...){... } - .------------------------------------------------------------------------- return ; .------------------------------------------------------------------------- : int y;... y = func(5); /* a */...... /* b */ : y = func(5); 1) " ", - , - . 2) func. int func(int x){... func(5). , x 5. ( ) int x; x = 5; return x+1; 3) x+1 6. return. : " " - func, . y = func(5); func(5) , return; y = 6; 4) . ------------------------------------------------------------------------- int y, z, w; y = func(5); z = func(6); w = func(7) + func(8) + 1; y = 6; z = 7; w = 8 + 9 + 1; "" func(), x .

. main(), main . ( ; ). main() - . ------------------------------------------------------------------------- : #include <stdio.h> /* */ /* ( ) */ int a = 7; int b; /* 0 */ /* */ f1(){....} f2(){....} /* () */ void main(){... }------------------------------------------------------------------------- : #include <stdio.h> int f1(int x, int y){ return (x + y*2);} int f2(int x){ int z; z = x+7; return 2*z;} void main(){ /* */ int a, b, c; /* */ a = 5; b = 6; c = f1(a, b+3); b = f1(1, 2); a = f2(c); printf("A %d B %d C %d\n", a, b, c);} : A 60 B 5 C 23

int i; for(i=0; i < 4; i++){ if(i == 0) func0(); else if(i == 1) func1(); else if(i == 2) func2(); else if(i == 3) func3(); } ., , : func0(); func1(); func2(); func3(); , , , func(i). i. , : int i; for(i=0; i < 10; i++){ if(i==0) func0(); else if(i == 1) func1(); else if(i == 2) func2(); else funcN(i); } funcN(i) " "., : int i; func0(); func1(); func2(); for(i = 3; i < 10; i++) funcN(i); , 3. - , : int i; for(i=0; i < 100; i++){ if((i % 2) == 0) even(); /* */ else odd(); /* */ } i.

C

/* */ #include <stdio.h> /* putchar('c') - c *//* \n - *//* nstars - */ /* */void drawOneLine(int nstars){ int i; /* , */ for(i=0; i < nstars; i++) /* nstars */ putchar('*'); putchar('\n'); /* */} void main(){ /* */ int nline; /* */ /* () */ for(nline=1; nline <= 25; nline++) drawOneLine(nline); /* ? , */}

C

/* *//* , */ #include <stdio.h> void main(){ /* */ int nline; /* */ int i; /* , */ /* () */ for(nline=1; nline <= 25; nline++){ /* ? , */ for(i=0; i < nline; i++) putchar('*'); putchar('\n'); }}

C

/* *//* */ #include <stdio.h> /* nstars - *//* nspaces - */ void drawOneLine(int nspaces, int nstars){ int i; /* , */ /* - */ for(i=0; i < nspaces; i++) putchar(' '); for(i=0; i < nstars; i++) putchar('*'); putchar('\n');} /* n ( )...* 1..*** 2.***** 3 ******* 4 : LINES n- : n*2 - 1 ( ): LINES - n ... drawOneLine __, . , - , . , , . */void main(){ /* */ int LINES = 25; /* . */ int nline; /* */ /* () */ for(nline=1; nline <= LINES; nline++) drawOneLine(LINES - nline, /* --> nspaces */ nline*2 - 1 /* --> nstars */);}

C

/* *//* */ #include <stdio.h> void drawOneLine(int nspaces, int nstars){ int i; /* , */ /* - */ for(i=0; i < nspaces; i++) putchar(' '); for(i=0; i < nstars; i++) putchar('*'); putchar('\n');} void main(){ /* */ int LINES = 25; /* . */ int nline; /* */ /* 1. - . for(nline=1; nline <= LINES; nline++) for(nline=0; nline < LINES; nline++) 25 , - nline 1 . . n ( )...* 0..*** 1.***** 2 ******* 3 : LINES n- : n*2 + 1 ( ): LINES - n - 1 */ /* () */ for(nline=0; nline < LINES; nline++) drawOneLine(LINES - nline - 1, nline*2 + 1);}

C

/* char ( character). 'a' 'b' '+'. : char letter; letter = 'a'; putchar(letter); letter = 'b'; putchar(letter); letter = '\n'; putchar(letter); '\n' " " - , new line. , - . . \ '\\' putchar('\'); printf ("\"); . : putchar('\\'); printf("\\"); , \ , , .*/ /* n, n 0, (x % n) == 0 , /, x%2. x n 0 1 2... n-1. 2 0 x 1 x */ /* : *--------------------------------------------------------* : , drawOneLine - symbol - . . */ #include <stdio.h> void drawOneLine(int nspaces, int nsymbols, char symbol){ int i; /* */ for(i=0; i < nspaces; i++) putchar(' '); for(i=0; i < nsymbols; i++) putchar(symbol); putchar('\n');} /* , "", . */int LINES = 25; /* . */ void main(){ /* */ int nline; /* */ /* () */ for(nline=0; nline < LINES; nline++){ if((nline % 2) == 0) /* ? */ drawOneLine(LINES - nline - 1, nline*2 + 1, '+'); else drawOneLine(LINES - nline - 1, nline*2 + 1, '*'); }}

C

/* , . */ #include <stdio.h> /* - . */ int LINES = 25; /* . */ /* , - . drawLineNumber. drawOneLine()! - - . if(x).....; ( ): ( int). , x!= 0, , x == 0. - .*/void drawOneLine(int nspaces, int nsymbols, char symbol, /* */ int drawLineNumber, int linenum){ int i; /* */ if(drawLineNumber) printf("%d\t", linenum); /* */ /* if(drawLineNumber!= 0) . */ /* \t - . ( ) 8 . :| | | | | | | | |... . | | | | | | | | |... ^ | | | | | | | | |... ^ */ for(i=0; i < nspaces; i++) putchar(' '); for(i=0; i < nsymbols; i++) putchar(symbol); putchar('\n');} void main(){ /* */ int nline; /* */ /* () */ for(nline=0; nline < LINES; nline++){ if((nline % 2) == 0) /* ? */ drawOneLine(LINES - nline - 1, nline*2 + 1, '+', 1, nline); else drawOneLine(LINES - nline - 1, nline*2 + 1, '*', 9, nline); } /* 1 9? * , 0. * 3, 333, 666, -13445, * * : , 0? */}

C

/* , : *+*+*+*.....*+* .*/ #include <stdio.h> int LINES = 25; /* . */ void drawOneLine(int nspaces, int nsymbols){ int i; for(i=0; i < nspaces; i++) putchar(' '); /* . */ for(i=0; i < nsymbols; i++){ if((i % 2) == 0) putchar('*'); else putchar('+'); } putchar('\n');} void main(){ int nline; /* */ for(nline=0; nline < LINES; nline++) { drawOneLine(LINES - nline - 1, nline*2 + 1); }}

C

/* : * *** ***** *** **/ #include <stdio.h> int LINES = 10; /* . */ void drawOneLine(int nspaces, int nsymbols){ int i; for(i=0; i < nspaces; i++) putchar(' '); for(i=0; i < nsymbols; i++) putchar('+'); putchar('\n');} void main(){ int nline; /* */ for(nline=0; nline < LINES; nline++) drawOneLine(LINES - nline - 1, nline*2 + 1); /* . . . : LINES-2 0 */ for(nline=LINES-2; nline >= 0; nline--) drawOneLine(LINES - nline - 1, nline*2 + 1);}

C

/* , . */ #include <stdio.h> void draw(int nspaces, int nstars, char symbol){ int i; for(i=0; i < nspaces; i++) putchar(' '); for(i=0; i < nstars; i++) putchar(symbol); putchar('\n');} void main(){ int LINES = 21; int MIDDLELINE = LINES/2 + 1; /* */ int nline; for(nline=0; nline < MIDDLELINE; nline++) draw(MIDDLELINE - nline -1, nline*2+1, 'A'); /* for() . nline , , , MIDDLELINE. */ for(; nline < LINES; nline++) draw(nline - MIDDLELINE + 1, (LINES - 1 - nline) * 2 + 1, 'V');}

* 12_ARRAYS.txt *

- , . . N , - var. - var[0] var[1]... var[N-1] . -------- / var / / / ------------------------------------------- ------------------ | | | | | | | | | |....... | | | | | | | | ------------------------------------------- ------------------ / var[0] / / var[1] / / var[2] / / var[N-1] / --------- --------- --------- ----------- : int var[N]; N - , . N int var[0]... var[N-1]; n- ( 0 <= n < N) var[n] n - ( , ), " ". [] " ". - N . var - (N ) n - (), 0..N-1 var[n] - . . n - - "" . : int var[5]; /* 1 */ var[0] = 2; /* 2 */ var[1] = 3 + var[0]; /* 3 */ var[2] = var[0] * var[1]; /* 4 */ var[3] = (var[0] + 4) * var[1]; /* 5 */ printf("var %d\n", var[3]); : var[0] var[1] var[2] var[3] var[4] ------------------------------------------------/* 1 */ /* 2 */ 2 /* 3 */ 2 5 /* 4 */ 2 5 10 /* 5 */ 2 5 10 30 , . - , , var0, var1, var2,... :var[0], var[1], var[2],... - . - 1) 2) - , - , .--------------------------------------------------------------------- , , (, ). printf("var4 %d\n", var[4]); . ( ). , . , .--------------------------------------------------------------------- , . int a[5]; int b[5]; a = b; /* */ () : a = 0; /* */ , , . : int i; for(i=0; i < 5; i++) /* i a[i] = 0; */ a[i] = 0; --------------------------------------------------------------------- ======================= ( ), ( ) . int i; for(i=0; i < 5; i++) a[i] = b[i]; . . : int index, array[5]; for(index=0; index < 5; index++) array[index] = index * 2 + 1; int index, array[5]; index = 0; while(index < 5){ array[index] = index * 2 + 1; index++; } /* : { 1, 3, 5, 7, 9 } */ - "/" . - , . . : ; : int a[N], i; for(i=0; i < N; i++)...a[i]...---------------------------------------------------------------------: int a[5]; a[0] = 17; a[0] += 4; a[0]++;---------------------------------------------------------------------: . : f[1] = 1 f[2] = 1 f[n+2] = f[n+1] + f[n] :------------------#include <stdio.h> /* */#define N 20 /* */ void main(){ int fibs[N], index; fibs[0] = 1; /* !!! */ fibs[1] = 1; /* , */ for(index=2; index < N; index++) fibs[index] = fibs[index-1] + fibs[index-2]; /* */ for(index = N-1; index >= 0; index--) printf("%d- %d\n", index+1, fibs[index]);} #define N 20, const int N = 20; , , #define - .

- char, \0 char string[20]; string[0] = ''; string[1] = ''; string[2] = ''; string[3] = ''; string[4] = ''; string[5] = ''; string[6] = '\0'; printf("%s\n", string); %s - . . char string[20]; string[0] = ''; string[1] = ''; string[2] = ''; string[3] = ''; string[4] = ''; string[5] = ''; string[6] = '\n'; /* - */ string[7] = '\0'; printf("%s", string); printf(string); "" char string[20] = "\n"; string[8] string[19] . " "?================================================= - . , ( )., - ( ). :(1) . ( ). char str[32]; /* */ int slen; /* slen */... func(str, &slen); /* */... , : . . (2) str[0], - str[1]... . , str[0] 0 255, - . (3) , - . func(str); /* - */ , , : int strlen(char s[]){ /* */ int counter = 0; /* */ while(s[counter]!= '\0') /* */ counter++; /* */ return counter; /* , '\0' */} . , . strlen(s) ( , ).--------------------------------------------------------------------- =================================, - , : int array[5] = { 12, 23, 34, 45, 56 }; char string[7] = { '', '', '', '', '', '', '\0' }; , , ( int) '\0' char. int array[5] = { 12, 23, 34 }; , - . int a[5] = { 177, 255, 133 }; a[] : n a[n] ---------------------------------------------1 (: " ")0 1771 2552 1333 04 05 ()

* 13_FUNCS.txt *

============================ , . /* func(). */ /* func - . . */ int func(int a, int b, int c){ int x, y;... x = a + 7;... b = b + 4;... return(_); } a, b, c - () x, y - - - , main() main(){ int zz, var;... var = 17; zz = func(33, 77, var + 3) + 44;...} zz = func(33, 77, var + 3) + 44; 1) func() (a) . (b) a, b, c, x, y; (c) - , . ( ) (): func(1, 2, 3) 1-, 2- 3- () : int func(a, b, c){ /* a = 1, b = 2, c = 3 */ : a = 33; : b = 77; : c = var + 3; , , c = 20; x y , ( , - ). 2) , , {... } . : x = a + 7; , - , . b = b + 4; . ( ). 3) .... return(_); } , ... return(a + 2 * x); } , : zz = func(33, 77, var + 3) + 44; (1) func(.....) zz = XXXXXXX + 44; (2) "_" return, . 128. (3) func(.....) zz = 128 + 44; (4) : a - b - c - x - y - ( ) . (5) , . (6) : zz = 128 + 44; zz = 172; /* */ ------------------------------------------------------------------------- int func1(int x){ printf("func1: x=%d\n", x); /* 1 */ x = 77; printf("func1: x=%d\n", x); /* 2 */ return x;} void main(){ int var, y; var = 111; y = func1(var); /* @ */ printf("main: var=%d\n", var); /* 3 */} @ func1() var, 111. , x 111 x = 111; printf() 111. x 77. x, var!!! ( ) var x, var - ( - ). printf() 77. var 111, printf, 111. ------------------------------------------------------------------------- ============================= int func1(int x){ /* f.1 */ printf("func1: x=%d\n", x); /* f.2 */ x = 77; /* f.3 */ printf("func1: x=%d\n", x); /* f.4 */ return x; /* f.5 */} void main(){ int x, y; /* 1 */ x = 111; /* 2 */ y = func1(x); /* 3 */ printf("main: x=%d y=%d\n", x, y); /* 4 */} main(), func1() . ? , . func1() x, () (). , : main::x func1::x ( ++, ). : |/* 1 */ main::x main::y ;|/* 2 */ main::x = 111;|/* 3 */ func1(111);|+-------+. |/* f.1 */ func1::x 111;. |/* f.2 */ 111 func1::x;. |. |/* f.3 */ func1::x = 77; ( main::x, ,. | func1.. | main::x -. | "" . | .. | ).. |. |/* f.4 */ 77 func1::x;. |/* f.5 */ func1::x, 77.. | func1::x .. |. | main(),. | x main::x. | func1::x+-------+||/* 3 */ y = 77;|/* 4 */ main::x main::y, | 111 77. main() func1() , , . - , . - x, i. ------------------------------------------------------------------------- , . int func1(int arg){ /* - func1::arg */ int x; /* func1::x */ x = arg; printf("func1: x=%d\n", x); x = 77; printf("func1: x=%d\n", x); return x;} void main(){ int x, y; /* main::x main::y */ x = 111; y = func1(x); printf("main: x=%d y=%d\n", x, y);} x. , : , _(...,...,....) 1 2 3 . : int f(int 1, int 2, int 3){ int 1, 2;... /* */} :.... f(1, 2, 3)... ( ): 1 = 1; 2 = 2; 3 = 3; 1 = ; 2 = ;... /* */ ------------------------------------------------------------------------- ===================== , , , ( , , ). . - . int x = 12; /*::x - */int globvar; /*::globvar */ int f1(){ int x; /* f1::x */ x = 77; printf("x=%d\n", x); /* 4 */ return x;} int f2(){ printf("x=%d\n", x); /* 5 */ return 0;} void main(){ int x, y; /* main::x */ x = 111; /* 1 */ printf("x=%d\n", x); /* 2 */ printf("glob=%d\n", globvar); /* 3 */ y = f1(); y = f2();} :- - . .- - "x". ? /* 1 */ main::x = 111; x, . x 12. /* 2 */ main::x, 111. main ::x x. main x, ++ ::x globvar . /* 3 */ ::globvar. , 0. , , 0. , . /* 4 */ f1() f1::x main::x ::x 77, ::x main::x x = 77. f1::x /* 5 */ f2() . x. -::x main::x? :::x 12. , . . ( "?" ) , funca(){ int vara;......funcb();... /* */... } funcb() vara. funcb(){ int z; z = vara + 1; /* , vara funcb() */ } , , funcb() funcc(), funcc() vara . . - , , . , , . . (a). (a) . ~~~~~~~~~~ : (5) . , , . -------------------------------------------------------------------------========= , . void (""). . void func(){ printf("!\n"); return; /* */ } " ", ( ). int glob; void func(int a){ glob += a; } return , } : main(){ int z; z = func(7); /* , ??? */} : main(){ func(7);} .

?

! int res1, res2;... res1 = func(12 * x * x + 177, 865, 'x'); res2 = func(432 * y + x, 123 * y - 12, 'z'); , , ; , ? , , (). , . : , "" . - , . - .------------------------------------------------------------------------- return , . . int f(int x){ int y; y = x + 4; if(y > 10) return (x - 1); y *= 2; return (x + y); }

.

, . int factorial(int arg){ if(arg == 1) return 1; /* a */ else return arg * factorial(arg - 1); /* b */ } factorial(n) n * (n-1) *... * 3 * 2 * 1 " n". arg ( ) . factorial::arg : factorial::arg[_] . factorial(4) +----------------------------------------+ | | factorial::arg[ 0__ ] 4 | | | factorial::arg[ 1__ ] 3 | | | factorial::arg[ 2__ ] 2 | | | factorial::arg[ 3__ ] 1 | V --------+ +--------- : +----------------------------------------+ A | /* b */ return 4 * 6 = 24 | | | /* b */ return 3 * 2 = 6 | | | /* b */ return 2 * 1 = 2 | | | /* a */ return 1; | | --------+ +--------- (stack). --------+ +------------ | | +---------------+ a | --------+ | +------------ | V | +---------------+ | a | <--- +---------------+ b --------+ +------------ | | +---------------+ | b | <--- +---------------+ | a | +---------------+ c --------+ +------------ | | +---------------+ | c | <--- +---------------+ | b | +---------------+ | a | +---------------+ , " " : c, b, a. () , . factorial::arg ( - arg) - , . , , () . - . , : int stack[10]; int in_stack = 0; /* */ /* */ void push(int x){ stack[in_stack] = x; in_stack++; } /* */ int pop(){ if(in_stack == 0){ printf(" , .\n"); return (-1); } in_stack--; return stack[in_stack]; } , ( ) , . , . void main(){ push(1); push(2); push(3); while(in_stack > 0){ printf("top=%d\n", pop()); } }

" ", . return . : int x = 7; /* */int v = 333; /* */ int factorial(int n){ int w; /* , */ w = n; if(n == 1) return 1; /* #a */ else return n * factorial(n-1); /* #b */}void func(){ int x; /* func::x */ x = 777; /* #c */ printf(" func()\n");}void main(){ int y = 12; /* main::y */ int z; /* A */ z = factorial(3); /* B */ printf("z=%d\n", z); func(); /* C */}------------------------------------------------------------------------- main(). /* A */ | | V V --------+ +-------- |=======================| | z = | | y = 12 | +------+---------+ |main() | |x = 7 | v = 333 | +-----------------------+-----------+------+---------+----- , a) ( ) .b) . "" : main::z, main::y,::x,::v ------------------------------------------------------------------------- /* B */ factorial(3). --------+ +-------- |=======================| | w = | | n = 3 | |factorial(3) | |=======================| | +-|---> z = factorial(3); | z = | | y = 12 | +------+---------+ |main() | |x = 7 | v = 333 | +-----------------------+-----------+------+---------+----- : factorial(3)::w, factorial(3)::n,::x,::v : main::z, main::y " ..." , , .------------------------------------------------------------------------- factorial(3) /* #b */ return 3 * factorial(2). factorial(2). --------+ +-------- |=======================| | w = | | n = 2 | |factorial(2) | |=======================| | +-|---> return 3 * factorial(2); | w = 3 | | n = 3 | |factorial(3) | |=======================| | +-|---> z = factorial(3); | z = | | y = 12 | +------+---------+ |main() | |x = 7 | v = 333 | +-----------------------+-----------+------+---------+----- ------------------------------------------------------------------------- factorial(2) /* #b */ return 2 * factorial(1). factorial(1). --------+ +-------- |=======================| | w = | | n = 1 | |factorial(1) | |=======================| | +-|---> return 2 * factorial(1); | w = 2 | | n = 2 | |factorial(2) | |=======================| | +-|---> return 3 * factorial(2); | w = 3 | | n = 3 | |factorial(3) | |=======================| | +-|---> z = factorial(3); | z = | | y = 12 | +------+---------+ |main() | |x = 7 | v = 333 | +-----------------------+-----------+------+---------+----- ------------------------------------------------------------------------- factorial(1) /* #a */ return 1. return , " " , ., factorial(m) . : return, return. . --------+ +-------- |=======================| | +-|---> return 1; | w = 1 | | n = 1 | |factorial(1) | |=======================| | +-|---> return 2 * factorial(1); | w = 2 | | n = 2 | |factorial(2) | |=======================| | +-|---> return 3 * factorial(2); | w = 3 | | n = 3 | |factorial(3) | |=======================| | +-|---> z = factorial(3); | z = | | y = 12 | +------+---------+ |main() | |x = 7 | v = 333 | +-----------------------+-----------+------+---------+----- ------------------------------------------------------------------------- return; --------+ +-------- |=======================| | +-|---> return 2 * 1; | w = 2 | | n = 2 | |factorial(2) | |=======================| | +-|---> return 3 * factorial(2); | w = 3 | | n = 3 | |factorial(3) | |=======================| | +-|---> z = factorial(3); | z = | | y = 12 | +------+---------+ |main() | |x = 7 | v = 333 | +-----------------------+-----------+------+---------+----- --------+ +-------- |=======================| | +-|---> return 3 * 2; | w = 3 | | n = 3 | |factorial(3) | |=======================| | +-|---> z = factorial(3); | z = | | y = 12 | +------+---------+ |main() | |x = 7 | v = 333 | +-----------------------+-----------+------+---------+----- --------+ +-------- |=======================| | +-|---> z = 6; | z = | | y = 12 | +------+---------+ |main() | |x = 7 | v = 333 | +-----------------------+-----------+------+---------+----- --------+ +-------- |=======================| | z = 6 | | y = 12 | +------+---------+ |main() | |x = 7 | v = 333 | +-----------------------+-----------+------+---------+----- -------------------------------------------------------------------------, /* C */ func(). /* #c */ . --------+ +-------- |=======================| | x = 777; | |func(); | |=======================| | +-|---> func(); | z = 6 | | y = 12 | +------+---------+ |main() | |x = 7 | v = 333 | +-----------------------+-----------+------+---------+----- - ?: func::x = 777::v = 333 .::x . main::y, main::z , ------------------------------------------------------------------------- ., ( ). - . int fibonacci(int n){ if(n==1 || n==2) return 1; /* else */ return fibonacci(n-1) + fibonacci(n-2);}void main(){ printf("20 %d\n", fibonacci(20));} , . - . - , fibonacci(1)? int called = 0; int fibonacci(int n){ if(n==1){ called++; return 1; } else if(n==2) return 1; return fibonacci(n-1) + fibonacci(n-2);}void main(){ printf("20 %d\n", fibonacci(20)); printf("fibonacci(1) %d \n", called);} ... 2584 !

C

/* */#include <stdio.h> const int LINES = 15; void draw(int nspaces, int nstars, char symbol){ int i; for(i=0; i < nspaces; i++) putchar(' '); for(i=0; i < nstars; i++) putchar(symbol);} void main(){ int nline, nsym; char symbols[3]; /* */ symbols[0] = '\\'; symbols[1] = 'o'; symbols[2] = '*'; for(nline=0; nline < LINES; nline++){ for(nsym = 0; nsym < 3; nsym++) draw(nline, nline, symbols[nsym]); /* */ putchar('\n'); }}

C

/* : ... , , , , ... 6 .*/ #include <stdio.h> /* */ /* . - . */ int TOMCATS = 3; /* */int CATS = 2; /* */int ANIMALS_PER_LINE = 6; /* */int LINES = 25; /* */ /* - . , ... - . - main().*/int ANIMALS; /* */ int nth_in_line = 0; /* *//* , * . , * . - . */ /* , , ().*/void checkIfWeHaveToBreakLine(){ nth_in_line++; /* ( ) */ if(nth_in_line == ANIMALS_PER_LINE){ /* ... */ putchar('\n'); /* */ nth_in_line = 0; /* */ } else { putchar('\t'); /* */ }} void main(){ int nanimal; /* */ int i; /* */ ANIMALS = ANIMALS_PER_LINE * LINES; nanimal = 0; while(nanimal < ANIMALS){ for(i=0; i < TOMCATS; i++){ /* printf() . ( putchar(). */ printf(""); nanimal++; /* */ /* - ? */ checkIfWeHaveToBreakLine(); } for(i=0; i < CATS; i++){ printf(""); nanimal++; /* */ /* - ? */ checkIfWeHaveToBreakLine(); } } /* putchar('\n'); */}

C

/* , . .*/ #include <stdio.h> /* */ int TOMCATS = 3; /* */int CATS = 2; /* */int ANIMALS_PER_LINE = 6; /* */int LINES = 5; /* */int ANIMALS; /* */ int nth_in_line = 0; /* */ void checkIfWeHaveToBreakLine(){ nth_in_line++; if(nth_in_line == ANIMALS_PER_LINE){ putchar('\n'); nth_in_line = 0; } else printf("\t\t"); /* @ */ /* {...} */} void main(){ int nanimal; int i; ANIMALS = ANIMALS_PER_LINE * LINES; nanimal = 0; while(nanimal < ANIMALS){ for(i=0; i < TOMCATS; i++){ /* %d int . ( - ). (). -- checkIfWeHaveToBreakLine() @. - putchar('a'); - printf("abcdef");


<== | ==>
- | : ,
:


: 2017-02-24; !; : 318 |


:

:

, .
==> ...

1466 - | 1375 -


© 2015-2024 lektsii.org - -

: 0.031 .