Документ взят из кэша поисковой машины. Адрес оригинального документа : http://ani.cmc.msu.ru/files/geo-2009-lect-02.pdf
Дата изменения: Thu Sep 17 12:07:26 2009
Дата индексирования: Mon Oct 1 19:36:57 2012
Кодировка:
,
. . http://ani.cmc.msu.ru/geol

2 -- . .

2009/2010 . .

. . ( )

2 -- ...

2009 ,

1 / 25



1 2

3

4

. . ( )

- C++ while for do-while break continue --

2 -- ...

2009 ,

2 / 25



-- && -- true , true -- || -- true , true -- ! -- true, false : x 2: (x > 0) && (x % 2 == 0) x 2 3: (x % 2 == 0) || (x % 3 == 0) : ((x % 2 == 0) || (x % 3 == 0)) && (x % 7 != 0) -- ?

. . ( )

2 -- ...

2009 ,

3 / 25


()
x 0 0 1 1 y 0 1 0 1 x && y 0 0 0 1 y false true false true x || y 0 1 1 1 !x 1 1 0 0 x || y false true true true !x true true false false

x false false true true

x && y false false false true

. . ( )

2 -- ...

2009 ,

4 / 25


h -- switc
1 switch ( /* 2{ 3 case /* 4 /* 5 brea 6 case /* 7 /* 8 brea 9 default : 0 /* 1 brea 2}
* / ) k k ; ; * / : * / * / : * /

* / k;

. . ( )

2 -- ...

2009 ,

5 / 25


:
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0

switch { ca ca ca ca ca ca

s s s s s s

( e e e e e e

case case defa }

month ) 1: 3: 5: 7: case 8: 10: 12: c o u t << 3 1 << e n d l break ; 4: case 6: case 9 c o u t << 3 0 << e n d l break ; 2 : / / c o u t << " 2 8 o r 2 9 " break ; ult : c o u t << " break ;

; : case 11: ; << e n d l ; " << e n d l ;
2009 , 6 / 25

. . ( )

2 -- ...


-


. . ( )

2 -- ...

2009 ,

7 / 25


C++

while c (while -- «») for while ( do-while -- « - »)

. . ( )

2 -- ...

2009 ,

8 / 25


while
1 w h i l e ( / * * / ) 2{ 3 / * * / 4}
( ), , ..

. . ( )

2 -- ...

2009 ,

9 / 25


while
6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
i n t N;


S=
N i =1

i

c o u t << " I n p u t N : " ; c i n >> N ; i n t sum = 0 , i = 1 ; w h i l e ( i <= N ) { sum = sum + i ; i = i + 1; } c o u t << " sum : " << sum << e n d l ; c o u t << "N * ( N+ 1 ) / 2 : " << N * ( N+ 1 ) / 2 << e n d l ;

. . ( )

2 -- ...

2009 ,

10 / 25


for
1 f o r ( _1 ; _2 ; _3 ) 2{ 3 ; 4}
for :

1 2 3 4 5 6

_1 ; w h i l e ( _2 ) { ; _3 ; }

. . ( )

2 -- ...

2009 ,

11 / 25


for
6 7 8 9 0 1 2 3 4 5 6 7 8 9



int n; c o u t << " I n p u t n : " ; c i n >> n ; i n t sum = 0 , i ; f o r ( i = 1 ; i <= n ; i = i + 1 ) { sum = sum + i ; } c o u t << " sum : " << sum << e n d l ; c o u t << " n * ( n + 1 ) / 2 : " << n * ( n + 1 ) / 2 << e n d l ;

. . ( )

2 -- ...

2009 ,

12 / 25


for
1 2 3 4 5 6

( )

i n t sum = 0 ; f o r ( i n t i = 1 ; i <= n ; ++ i ) { sum += i ; }

. . ( )

(int i = 1); i = i + 1; ++i; (, ) sum = sum + i; sum += i;

2 -- ...

2009 ,

13 / 25


for

( )

1 2 3 4 5 6

i n t sum = 0 ; f o r ( i n t i = n ; i >= 0 ; i = i - 1 ) { sum += i ; }

. . ( )

2 -- ...

2009 ,

14 / 25


do-while («, »)
1 2 3 4 5
do { / * * / } w h i l e ( / * * / ) ;

, while , , do-while

. . ( )

2 -- ...

2009 ,

15 / 25



1 while ( true ) 2{ 3 / * * / 4} 1 2 3 4 5
do {

/ * * / } while ( true ) ;

:

1 for ( ; ; ) 2{ 3 / * * / 4} . . ( ) 2 -- ... 2009 , 16 / 25


break --
break, ,

1 for ( ; ; ) 2{ 3 / * * / 4 5 i f ( / * * / ) 6 { 7 / * * / 8 break ; 9 } 0} . . ( ) 2 -- ... 2009 , 17 / 25


continue --
while do-while for -- , , (if-else)

1 for ( ; ; ) 2{ 3 i f ( / * * / ) 4 { 5 / * * / 6 continue ; 7 } 8 / * * / 9} . . ( ) 2 -- ... 2009 , 18 / 25


continue
1 for ( ; ; ) 2{ 3 int n; 4 c i n >> n 5 6 i f (n < 7 cont 8 9 / * 0}

; 0) inue ; * /

. . ( )

2 -- ...

2009 ,

19 / 25


-- while
x3 x5 + - ··· = 5! 3!




S (x ) = x -

(-1)n
n =0

x 2n+1 = (2n + 1)!



fn (x ),
n =0

f

n+

x 2n+1 fn (x ) = (-1)n , (2n + 1)! x 2n+3 fn+1 (x ) = (-1)n+1 , (2n + 3)! x2 1 (x ) = -fn (x ) · (2n + 2)(2n + 3)

. . ( )

2 -- ...

2009 ,

20 / 25


-- while
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 #i n #i n usi int { c l u d e c l u d e n g namespace s t d ; main ( ) double x , eps ; c o u t << " I n p u t x : " ; c i n >> x ; c o u t << " I n p u t e p s : " ; c i n >> e p s ; double f = x , S = x ; int n = 0; while ( fabs ( f ) > eps ) { f = -f x x / ( ( 2 * n + 2 ) * ( 2 * n + 3 ) ) ; S += f ; * * ++n ; } c o u t << " S ( x ) : " << S << e n d l ; c o u t << " s i n ( x ) : " << s i n ( x ) << e n d l ; return 0; 2 -- ...



}

. . ( )

2009 ,

21 / 25



( ): variable = variable + 1; ++variable; ( ) variable++; ( ) ( 1): variable = variable ­ 1;

--variable; ( )
variable--; ( )

. . ( )

2 -- ...

2009 ,

22 / 25



: , : ,

6 7 8 9 0 1 2 3 4 1 2 3 4 5

i n t var ; var = 1 ; c o u t << " p o s t f i x : " << v a r++ << e n d l ; c o u t << " v a l u e : " << v a r << e n d l << e n d l ; var = 1 ; c o u t << " p r e f i x : " << ++v a r << e n d l ; c o u t << " v a l u e : " << v a r << e n d l ; postfix : 1 value : 2 prefix : 2 value : 2

. . ( )

2 -- ...

2009 ,

23 / 25



i=i+2 , i += 2 +=, =, +=

-=

*=

/=

%=

x *= y + 1 x = x * (y + 1) x=x*y+1 , , : x1 = (-b + (sqrt_d = sqrt(b*b - 4*a*c))) / (2*a); x2 = (-b + sqrt_d) / (2*a);

. . ( )

2 -- ...

2009 ,

24 / 25



! * ++ /

--
%

+ -

+ -

<
== && || =

<=
!=

>

>=

+=

-=

*=

/=

%=

. . ( )

2 -- ...

2009 ,

25 / 25