.
( ) © Copyright  Email: abs@opentech.olvit.ru mailto:abs@opentech.olvit.ru ---------------------------------------------------------------  - "" , . , . , "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. 03.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); /* ? , */ } 04.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'); } } 05.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 */ ); } 06.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); } 07.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, '*'); } } 08.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 ? */ } 09.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); } } 10.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); } 11.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') /* */ cou