Вы находитесь на странице: 1из 104

.......................................................................................................................................

2
1. Visual C++
2008 ...............................................................................................................................................4
........................................................................................................23
2. ........................................................................................24
2.1. ................................................24
.............................................................................................................24
............................................................................................25
.............................................26
.....................................................28
............................................................................................29
.................................................................32
.............................................................................36
2.2 , ..............................................38
2.3 .......................................................................................39
2.1 ......................................................................................39
2.2 ......................................................................................40
2.4. ......................................................................42
2.5. .......................................................................45
........................................................................................................50
3. ...........................................................................51
3.1 ...................................51
.........................................................................................................51
.....................................................................................54
( ) ..................................................................55
3.2. ......................................................................................55
3.3. ..........................................................................60
........................................................................................................66
4. ...................................................................................67
4.1. ...........................................67
(for)....................................................................................................67
(while)............................................................................................70
(do while) .......................................................................................70
4.2. .............................................................72
4.3. while ...................................76
4.4. for ......................................79
4.5. ..........................................................................81
4.6. .........................................................95
4.7. .........................................................................................97
4.8. ..........................................................................99
......................................................................................................102
......................................................................................104

.
, .
(
) ,
,
. , ,

.

, . ,
, ,

. .

,
, .
, ,
.


(, , , )
,
. . , . . C VS C++

3
. , .
,
. , .
C MS Visual Studio, .
, Visual Studio ,
. , . , .

. . , . . C VS C++

1.
Visual C++ 2008
Visual C++
, ,
, .
,
, , , , , .
- ,
. 80, 50.
, .

, , BackSpace ( ), Delete ( ),
Insert ( ), ( ), ( ),
( ). , ,
,
,
.
Enter, .
,
,
.
, . ,
.
, , -

. . , . . C VS C++

5
, .

. 1.1
, , Visual C++ File/New/Project.... New Project
(. . 1.1) Win32, Win32 Console
Application, Location: ( , Browse)
, Name: OK,
- Finish Win32 Application Wizard.
, . 1.2.
(. . 1.2) -
( ).

// 1.cpp : Defines the entry point for the console application

( //) , .

. . , . . C VS C++

6

Standard

Edit

Debug

. 1.2

#include "stdafx.h", -

stdafx.h, () , ,

(primary function),

int _tmain(int argc, _TCHAR* argv[])
,
return 0;
0.

. . , . . C VS C++

7
(
), Debug , Build/Build Solution.
( ). Visual C++ Debug/Start Without Debugging
( ),

, Ctrl+F5. -

(. 1.3) ,
return 0;,
, .

1.3.
Debug/Start Debugging ( ),

, F5,

, ,
. ,
return 0; getch();
#include "conio.h"
#include "stdafx.h"
#include "conio.h"

int _tmain(int argc, _TCHAR* argv[])


{
getch();
return 0;
}
,
Windows.

. . , . . C VS C++

8
, , , , , , , #include,
.

. , .
:

//

// getch();
getch(); //

/* */, ,

, ,
/*

9,8

*/

/^2

,

int

_tmain(int

argc,

_TCHAR*

argv[/*

*/])

int _tmain(int argc/* */, _TCHAR* argv[])


, , /,

, (,

",

"conio.h")

.
. , \ .
, .

.
; ( ), , getch(); return 0; q++; (
. . , . . C VS C++

9
q 1), , , s=s+q++ ( s q,
q 1)
(. for 4.1) .
( ) ({)
(}). (, _tmain, . ), . ,
, , , , ()
. , , ,
. ,
( ), , return
, .
,
.
, ,
.
< > < > < >;

< > - : int (), float (), double ( ), char (),


< > - ,
< > - , , $ _
(), , $ _.
, .
,
.

. . , . . C VS C++

10
= (
).
,
, ( -), .
,
const.
int x, y=-5; /* int.
y
-5*/

int const n = 10; /*


int */
. , 10 ,
10. , 10 ,
(.
4.6).
,
9,8 /2 , .
#include "stdafx.h"
#include "conio.h"

/*

-, getch(); */
#include "math.h"

/*

*/
//
int _tmain(int argc, _TCHAR* argv[])
{
//

. . , . . C VS C++

11
float const g=9.8; /* ,

. */

float T;/* ,
. */

int S;// , .
//

// S
printf("Enter S: ");
// S
scanf("%d",&S);
//
T=sqrt(S*2/g);
//
printf("T=%f\n", T);
//
getch();
return 0;
}
_tmain ( g), T S, ,
. - .

,
.
() () :

, , OK. ,

. . , . . C VS C++

12

Visual C++ , .

Ruc .
#include "stdafx.h"
#include "conio.h"
//
// .
#include "math.h"
// Ruc, . .
char* Ruc(char s[]);

int _tmain(int argc, _TCHAR* argv[])


{
//

float const g=9.8; /* ,


. */

float T;/* ,
. */

int S;// , .
//

// S .
// \
// .

printf(Ruc(" , \
%f\n .\n"), g);
printf(Ruc(" : "));
// S.
scanf("%d",&S);
. . , . . C VS C++

13
// .

// sqrt .
T=sqrt(S*2/g);
// .

printf("%s T=%f", Ruc(" "), T);


printf("%s\n", Ruc(" ."));

// .
getch();
return 0;
}
char* Ruc(char s[])
{ //
// .
int i;
static char ss[257];
for (i=0;s[i] != '\0'; i++)
{
if (s[i]>= -64 && s[i] <= -17)
ss[i]=(-64+s[i]); //..
else if (s[i]>= -16 && s[i] <= 0)
ss[i]=(char)(-16+s[i]); //..
else if (s[i] == -72)
ss[i]=(char)(-15); //
else if (s[i] == -88)
ss[i]=(char)(-16); //
else
ss[i]=s[i];
}
ss[i]='\0';
return ss;
}
-

. . , . . C VS C++

14

, _tmain,
Ruc.
, . , ,
( , Ruc ).
, ,
. Visual C++ Project/Add New Item,
Header File.h, , (, ),
Add. ,
Solution Explorer ( View/Solution Explorer) , Visual C++
, (.h). #include
(#include ".h"). .

. . , . . C VS C++

15

. . , . . C VS C++

16

( ),
#include
(, #include "D:\temp\.h").

, (
), ,
( ).

Build/Build Solution Build/Rebuild Solution. Output . ,
, ,
.
Visual C++ C , warning.
. error.
C (,
, , , ) . .
.
,
.
. , , , ,
.
, . , Visual C++ .

. . , . . C VS C++

17

(), (). , ,
: , .
.
, . , . ,
, :

, , -

Visual C++

.
.
, ,
,
. ( ) .
, #define u1 ( , u1),
#ifdef u1
. . . //
. . . //
. . . //
#endif
#ifdef u1 ( u1 ) #endif ( #ifdef), . . , . . C VS C++

18
. ,
#define u1 .

///*
. . . //
. . . //
. . . //
//*/
. // ( /*// ).
,
. , , .
#define . #define
#ifdef, , , #define
debug1, #define debug2 .
#ifndef (
), #ifdef. , , , #define debug1
#ifdef debug1 // debug1 ,
. . . // ,
. . . //
#else //, .. debug1 ,
//
. . . //
. . . //
. . . //
#endif
. . , . . C VS C++

19

Visual C++.
Visual C++ (Debug)

(Edit)

Tools Customize

Debug Text Editor. Commands,

,
. . , . . C VS C++

20
Edit, Edit Visual C++ . , Customize
Debug. , Customize.
Debug :
- ,
Visual C++.
- .
,
(. ).
- , ,
.
- Watch
: , ,
.
,
. ( VS C++ 2008 Autos, )
- ( , ).
- (
,
).
-
.
( ). ,
.
.
Breakpoint/insert Breakpoint. . . , . . C VS C++

21
.
,
.

sqrt(S*2/g)
.

. . , . . C VS C++

22

) -

,
( T=sqrt(S*2/g);,
), -
printf("%s T=%f", Ruc(" "), T);

. . , . . C VS C++

23


1.

2.

3.

4.

5.

6.

7.

8.

9.

#include?

10. ?
11. ?
12. ?
13. ?
14. ?
15. Visual C++ ?
16. ?
17. ?
18. ?
19.
?
20. ?
21. ?
22. ?
23. ?
24. ,
, ?

. . , . . C VS C++

24

2.

,
.
,
, , .
.

2.1.

. ( C ) .


:
int , 231 +231-1 ( -2147483648
2147483647), 4 .
unsigned int , ( unsigned) 0 +232-1 ( 0 4294967295), 4 .
// I K
int I, K=-5;
// i k
unsigned int i, k=5;
//
//
const int Nmax=10;
//
(, , ). :
( -),
( +),

. . , . . C VS C++

25
( -),
( *),
( /),
( %).
/ , %
( ). ,
int I, K;
I = -5 / -2; //I 2

K = -5 % -2; //K -1
, , (. ).
, .


() :
float - ,
1.17549435110 38 3.40282346610+38, 4 .
double - ,

2.225073858507201410+308

1.797693134862315810+308, 8 .
, r float R double,

float r;
double R;
double
, , -12.345, ,
, , -0.12345E+2, -0.12345E2, 0.12345+2, 1.2345E+1, 1.2345E1, 12.345E0, 1234.5E-2,
12345E-3 .. , . , , , , -

. . , . . C VS C++

26
, 10 , , , .
, -0.12345E+2 0,1234510+2,

1234.5E-2 1234,510-2. float , , f


F, ,
-12.345f, -0.12345E2f, 12.345F, -0.12345E2F .. , .
Y float, Z double H
0,00000025:
float ,

Y;

double Z;
const float H=2.5E-7;
, , , :
( -),
( +),
( -),
( *),
( /).
BASIC Fortran, C
.


C
- ,
#include "math.h".( 584)

double, float, (
, , , ) .
. . , . . C VS C++

27
acos(X)

asin(X)

atan(X)


/2 +/2,

ceil(X)

,
,

cos(X)

exp(X)

ex,

fabs(X)

floor(X)

,
,

log(X)

log10(X)

X 10,

sqrt(X)

pow(X,Y)

X, Y,

sin(X)

tan(X)

double.
, float, ,
f, acosf(X), fabsf(X), powf(X,Y).
f, , ,
. , ,
.

,
, ,

(.
pow). ,
( ), X
, ,
X.

. . , . . C VS C++

28
C Floating-Point Support Search, math routines .


C
Visual C++ 2008.
C.
.
, , =.
( ,
), , ( ). ,
int I=5, K;
float X , Y=2.3;
double Z = 1.0e-2;
const float pi = 3.1415926535;
X = tan(pi/3); //X 1.732
. . , , , ,
K = -tan(pi/3); //K -1
. :
.
++
( +) -- ( -),
1 () 1 () , . , , 1, , , . ,
. . , . . C VS C++

29
I--; // , I = I-1;, -I;
++I; // , I = I+1;, I++;
, ( + - * / %) =. , X - , , W ,
X += W ;

// X = X + W,

X -= W;

// X = X W,

X *= W;
X /= W;
X %= W;

// X = X * W,

// X = X / W,
// X = X % W.



\ , , . .
,

.
,
, , . ,
6+tan(3*3.14/4)
4.9976, (+) - -1.0024 ( , 450),

6+(i=tan(3*3.14/4))
5, (+) i , -1, -1.0024 ( tan(3*3.14/4)) i.
(. ), ,
, . . , . . C VS C++

30
: . ,
6+(int)tan(3*3.14/4)
. , float
(e) , , ,
I%3, exp((float)i%3).
, , , . .
, (-), - (*, /, %) , (+ -)
.
(float double), , (double).
,

sin 2 ( X ) cos(Y 3 ) 12 10 5
X Y Z 2 / 3

pow(sin(X),2.0f)*cos(pow(Y,3))*1.2E-4/sqrt(X)/Y/pow(Z,2.0/3.0)

pow(sin(X),2.0f)*cos(pow(Y,3))*1.2E-4/sqrt(X)/Y/pow(Z,2.0/3.0)

, ,
.
double, , Z (. )
double.
C .
. . , . . C VS C++

31
(), (++)
(--) . ++ -- , , , . ++ --
( ),
( ). , ,
. , j 2 k -3,
i=2*k--+-++j
i -9, k -4, j 3. : ++j j 3,
, ,
j, -3, , 2*k k -6
-3 ( -j), k 1 -4.
, :
j=j+1; i=2*k-j; k=k-1;
i, k j
, ,
.
k :
i=2*--k+-++j;
i -11, 2 k
-4.
. ,
. , , , , .
, S V R L

V=L*(S=3.1415926535*R*R)
. . , . . C VS C++

32
, ,
X=Y=Z=3.5
X, Y Z 3,5. .


C printf.
(, , ),
, , printf, ,
.
printf ,
, (
, ), . .
,
%.
:
%d ,
%u ,
%f float ,
%lf double ,
%e ,
%g :
.
, ,
: , ..
,
int k=-25;
unsigned int j=7;
float x=-4.55;
. . , . . C VS C++

33
double y=3.125E-2;

printf("%d%u%f%lf",k,j,x,y);

-257-4.5500000.031250
"%d%u%f%lf"
, ,
( 7, j, -25, k, , -2 57,
-25 7; ).
, , (, ) , (, ), . .
1. :

printf("k=%d j=%u x=%f y=%lf",k,j,x,y);



k=-25 j=7 x=-4.550000 y=0.031250
2. :

printf("k=%d %u %f %lf",k,j,x,y);

-25 7 -4.550000 0.031250
3. (\t) :

printf("\n\t%d\t%u\t%f\t%lf\n",k,j,x,y);

-25

-4.550000

0.031250

4. (\n) :

printf("%d\n%u\n%f\n%lf\n",k,j,x,y);
,
. . , . . C VS C++

34
-25
7
-4.550000
0.031250
5.
printf("\tk\tj\tx\t\ty\n");

printf("\t%d\t%u\t%f\t%lf\n",k,j,x,y);

-25

-4.550000

0.0312507

\n ,
, , \n
, . , .
. ,
( ) .
, .

#include <stdafx.h>
#include <math.h>

int _tmain(int argc, _TCHAR* argv[])


{
int Fi;
float R;
//
printf("input Fi:");
// Fi
. . , . . C VS C++

35
scanf("%d",&Fi);
//
printf("Fi = %d\n",Fi);
// R
R=Fi*atan(1.0)/45;
// R ( )
printf("\nR = %f rad\n",R);//
// tg(R)
printf("\ntg(%lf) = %lf\n",R, tan(R));
return 0;
}
- 30 :
input Fi: 30
Fi = 30

R = 0.523599 rad

tg(0.523599) = 0.577350

( ) (
, ), ( , )
. ,
+.
,
( ), . , , ( ).
,
(-).
,
printf("\nR = %f rad\n",R);//
. . , . . C VS C++

36

printf("\nR = %30.18f rad \n",R);


30 18-
R =

0.523598790168762210 rad

( )
printf("\nR = %-30.18f rad\n",R);

R = 0.523598790168762210

rad

,
printf("\nR = %e rad\n",R);//

R = 5.235988e-001 rad

printf("\nR = %25.18e rad\n",R);


25 18-

R =

5.235987901687622100e-001 rad

( )
printf("\nR = %-25.18e rad\n",R);

R = 5.235987901687622100e-001

rad


C
scanf. (,
, ),
.
scanf , - ,
&. %:
%d ,
%u ,
. . , . . C VS C++

37
%f float,
%lf double.
,
int k;
unsigned int j;
float x;
double y;
,
scanf("%d %u %f %lf",&k,&j,&x,&y);
, (
Enter), ,
-25

77

5.71

1e-5


-25 77
5.71
1e-5
, scanf, ,
, .

-25

77

5.71

1e-5

, scanf,

scanf("%d %u",&k,&j);

scanf("%f %lf",&x,&y);
(
)
. , scanf, , . , ,
1. :
. . , . . C VS C++

38
scanf("%d %u %f %lf",&k,&j,&x,&y);
printf("%d \t%u \t%g \t%g",k,j,x,y);
2. if while (.
) scanf, , ( 0,
, 1,
..) ,
, - .

2.2 ,
, , .
, , , .
, ,
, , , . ,
, , , .
. ,
Z=sin(X)*Y-sin(X)*sqrt(Y)*Y+sqrt(X)*X+X;

Z=sin(X)*Y*(1-sqrt(Y))+X*(sqrt(X)+1);
. ,
2X5 - 5X 4 + 2X3 + 7X 2 - 4X + 6
,
((((2X-5)X+2)X+7)X-4)X+6
, , .

((((2*X-5)*X+2)*X+7)*X-4)*X+6,

2*pow(X,5)-5*pow(X,4)+2*pow(X,3)+7*pow(X,2)-4*X+6
. . , . . C VS C++

39
.
, :
1+2!+3!+4!+5! = 1+2(1+3(1+4(1+5)))
. ,

A = X Y

Z = (X Y)

1 + ( X Y )3
1 + ( X Y )2

B = A 2 , Z = A

1 + AB
.
1+ B

:
A=X-Y;
B=A*A;
Z=A*(1+A*B)/(1+B);

2.3
2.1
k0, k1, k2, k3 (0
X80)
:

X = k 3 3 3 + k 2 3 2 + k1 3 + k 0

(2.1)

(/)
(%).
(2.1) , (2.1) . .
X=(0; 1; 2; 10; 27; 48; 80).
+D:\temp\temp2-3-1 +)
#include <stdafx.h>
int _tmain(int argc, _TCHAR* argv[])
{
unsigned int X, k0, k1, k2, k3, X1, X2;
//
printf("input X: ");
scanf("%u",&X);

. . , . . C VS C++

40
//
k0=X%3; X=X/3;
k1=X%3; X=X/3;

//k0:= X 3;

//k1:= X/3 3;

k2=X%3;

//k2:= X/9 3;

k3=X/3;

//k3:=X/27;

//

// 3
printf("\nk3=%u

k2=%u

k1=%u

k0=%u",k3,k2,k1,k0);

//
// 1.

// (2.1)
X1=k3*27+k2*9+k1*3+k0;
//
printf("\nX1 = %u",X1);
// 2.
// (2.1),

//
X2=((k3*3+k2)*3+k1)*3+k0;
//
printf("\nX2 = %u\n",X2);
return 0;
}
- 77 :
input X: 77
k3=2

k2=2

k1=1

k0=2

X1 = 77
X2 = 77

2.2

x

( a ) lg( a + 1)

Y(X ) = 2

3
(a)
2

2
(a )2
2

(2.2)

. . , . . C VS C++

41
/ ( /
, , ). (2.2) .
X=(0,5; 2) A=(1; -1; 2; -2; 4; -4). , .

#include "stdafx.h"
#include "math.h"
int _tmain(int argc, _TCHAR* argv[])
{
double

A=2.0,

X=0.5, B, C, Y1, Y2;

//
printf("input X: ");
scanf("%lf",&X);
printf("input A: ");
scanf("%lf",&A);
//

// -
B=A/2;
C=B*B;
// - (2.2)}
Y2=(pow(A/2,X)-log10(A/2+1)) / (pow(A/2,3)
-pow(A/2,2));
//
printf("\n\t\tY1\t\t\tY2");
printf("\n\t\t%e\t\t%e\n",Y1,Y2);
return 0;
}
, :
1) ( log10) . . , . . C VS C++

42
(
pow),
2) ( ).

1)
input X: 2
input A: 1

Y1

Y2

-5.912699e-001

-5.912699e-001

2)
input X: 0.5
input A: -1

Y1

Y2

-1.#IND00e+000

-1.#IND00e+000

2) -1.#IND00e+000 . ,
. ,
, ,
. . ,
.
,
.

2.4.
1 28:
, / , ,

. . , . . C VS C++

43
,
.
1.

Z = X 2 Y 2 + 3 X Y 2 5 X 2 Y + X 2 2 Y 2 + 4 X Y X + Y , X=(2; -2), Y=( 4; -3).

2.

B=A+2; C=(A+3)/(A+2); D=(A+4)/(A+3); E=(A+5)/(A+4);

A=(1; 2; -2; 3; 4).

3.

( X + 2) 2 + 3
Z = ( X + 2)
;
( X + 2) 4 + ( X + 2) 2 + 3

X=(0; 1; 2; -2; 4).

4.
5.

6.

B=sinA; C=lgA; D=eA; E=|A|;


S=(A+B)(A+B+C)(A+B+C+D)(A+B+C+D+E);
B=A+5; C=A-2; D=B+C; E=A-C;
AC
AC E
A
AC
P1 = ; P 2 =
; P3 =
; P4 =
;
B
B
BD
BD
B=A-2; C=A+3; D=B+C; E=A-2;
P1=AB; P2=ABC; P3=ABCD; P4=ABCDE;

Y=

8.

Y = X 6 + A X 5 A2 X 4 + A3 X 3 A4 X 2 + A5 X A6 ,

9.

A 2 X A3 X 4 A 4 X 6
Y=A
,
+

3
35
357

10.

Y=X+

11.

Y =(

12.

Y =(

14.

A=(-15; -5; 0; 7; 14).

A=(-4; 0; 4; 7).

3
35
357
357 9

,
1+ 3 + X 1+ 3 + 5 + 2 X 1+ 3 + 5 + 7 + 3 X 1+ 3 + 5 + 7 + 9 + 4 X
X=(-9; -4; 0; 3; 9).

7.

13.

A=(8; -2; 4; -5).

Y=

Y=

15.

Y=

16.

Y=

X=(-3; 0; 3), A=4.

2 4 X 2 2 4 6 X 3 2 4 6 8 X 4 2 4 6 8 10 X 5
,
+
+
+
2+4
2+4+6
2+4+6+8
2 + 4 + 6 + 8 + 10
X=(-7; -2; 0; 2; 7).
1

A B ( A + B) 2 / 3 X 2 X
) ,
A4 + B 4 2 A2 B 2 X 4

X=(0,5; 1; 2), A=4, B=3.

A X
) + ( A )2 X + 2( A )2 / 3 log 2 ( A ) ,
B
B
B
B

3,3 10 4 tgX lg( X 2 5) | tgX |


3

X 2 5 X e 2 X

( X + 1) 2 ( X + 2) ln( X + 1)

( X + 2) 3 ( X + 2) 2 + ( X + 1) 2
3

X=(-3; 5), A=(-3;5).

X 4 + X 3 X 2 X +1
,
X 4 + 2X 3 2X 1

X + X 3 3
,
2X 2 4X + 2 + 6X 3 4X 5

X=(2,5; 5; 7; 10), A=4, B=3.

X=(1; 2,5; 5; 7; 10).

X=(-0,5; 5; 10; 25).

X=(-15; -5; -2; 2; 5).


X=(-5; -2; 2; 5).

. . , . . C VS C++

44
cos 4 X cos 2 X

ln(| cos X |) ,
4
2

17.

Y=

18.

1
( X 1) 2 ( X 1) 4
Y = ( + ( X 1)
+
) /( X 2 1) ,
2
2
3

19.

1
( + sin 2 X ) ln | sin X |
,
Y= 2

arcsin X
3

20.

Y=

X=(0; 30 o; 45 o; 60 o; 90 o).
X=(0; 1; 2; 3).

X=(0,001; 0,1; 0,3; 0,5; 0,9; 1,8).

e X e 2 X + e3 X arccos2 X
,
e X e 2 X + e3 X arcsin 0,5 X

| 1 A2tgX |

X=(0,001; 0,02; 0,1; 0,9).

21.

Y=

4
,
(sin X + cos X )(tg 2 X + 1)

X=(0,001 o; 15 o ; 30 o; 60 o; 135 o).

22.

Y=

| sin X cos X | +tgX


,
sin X + sin X cos X + cos X

X=(0,001o; 15 o ; 30 o; 60 o; 270 o).

23.

Y=

2X 3 + 6X 2 8X + 4
,
4X 3 + 8X 2 X 5 + 2X 4

24.

1 | log 2 X | + 25 10 5 log10 X
Y=
,
log 2 X + 0,00025 log10 X

25.

X=(-5; -2; 2; 5).

X=(0,001; 0,1; -1; 1; 4).

X lg( X + 1) + lg( X + 1) + X ln A + ln A + A X +1 lg( X + 1) + A X +1 ln A


,
Y=
ln A + ln( X + 1)
X=(0,001; 0,1; -1; 1; 4), A=3.
A X X A + 2 A2 X X A 2 A X X 2 A 4 A2 X X 2 A
,
lg A + lg X

26.

Y=

27.

AX X A
,
Y = A X
A + X A X

28.

Y = 1+

X=(0,001; 0,1; 1; 4), A=1,5.

A X

X2 X2 X2
X4
X4
X4
X6
+
+
+
+
+
+
,
32
7 2 112 3 2 7 2 3 2112 7 2112 3 2 7 2112

X=(0,001; 0,1; 1; 4) A=2.

X=(-4; 0; 4; 11).

29 30 k0, k1, k2,


(0X<PN) P, / %.
X P , .
. X .
. . , . . C VS C++

45
29.

P=8,

N=4,

X = k 4 84 + k 3 83 + k 2 82 + k1 8 + k 0 ,

M={0; 1; 2; 4; 7, 8; 65;

1023; 4095}.
30.

P=16, N=3,

X = k 3 163 + k 2 16 2 + k1 16 + k 0 , M={0; 1; 15; 64; 127; 255;

2047; 4095}.
31.

X, X2, X3 Y
X, X2, X3 Y.
, , , , . .
X=(-5; 5) Y=(-3; 3).
32.

X1, X2, Y1, Y2, Z1, Z2 (X1<X2, Y1<Y2, Z1<Z2), . I1, I2, J1, J2, K1, K2 , .
. X1, X2, Y1,
Y2, Z1, Z2 I1, I2, J1, J2, K1, K2 , . X1=(2,7; 5,2), X2=2X1, Y1=X1-1, Y2=2Y1,
Z1=

X1
, Z2=3Z1.
2

2.5.
:

,
1.

.
2.

S , -

, , , -

. . , . . C VS C++

46
S =

La Lb sin C
, La Lb, ,
2

, .
3.

, , -

, m:n:k. m, n k .
4.

. .
5.

Y=KX+B,

(X1, Y1) (X2, Y2),


.
.
6.

, -

: AX+BY=C DX+EY=F. .
7.

X0, Y0. -

A .
:
a) A=arctg(Y0/X0),
8.

b) A=,

c) A=arctg(Y0/X0)-/2.

, -

Y=k1X+b1 Y=k2X+b2 X. S
, .
Y=X+1 Y= -X+1.
9.

.
AX+BY=C, X2+Y2=R2. .
10.

S , -

R, La , . A .
,
.

. . , . . C VS C++

47
11.

Y=C/X.

AX2+BY2=R2 -

: A=B=C=1 R2=2

X1=X3=1,Y1=Y3=1 X2=X4=-1, Y2=Y4=-1.


12.

X Y, A, B.

, , , . A=1 B=0, .
13.

, -

, .
.
14.

X Y, A, B.

, , , .
A=1 B=1, .
15.

, La, Lb, Lc, , -

La, sin( ) =
2

( P Lb) ( P Lc )
,
Lb Lc

P . .
.
16.

,
2

X
Y = X + C + Y 2 = 1 . .
2

17.

N,

R. N
N, 6, 60 360. :
N=4 R 0,363.
18.

N, -

D. N
N, 12, 120, 720. : N=4 D 0,274.
19.

, -

R, A .
R .
R . . , . . C VS C++

48
A:
a) /3,

3 3R 2
,
4

b) /2, R2
20.

X Y, A, B.

, , , .
A=1 B=1, .
21.

, La, Lb, Lc, , -

La, cos( ) =
2

P ( P La )
, P
Lb Lc

. . .
22.

A (1, 2) (1, 3) -

, X1, Y1, X2, Y2,X3, Y3


(X1<X2<X3), L12, L13 S
S=L12L13Sin(A)/2. A .
X1=0, Y1=0, X2=1, Y2=0, X3=2 Y3=(2, -2).
23.

S ,

R, La ,
. L .
, .
24.

, -

R, , La .
La Lb . R=1 La= 2 + 2 , .
25.

, -

, 2/3 , .
. (0; 0), (3; 0), (0; 3), .
. . , . . C VS C++

49
S

26.
S=

La Lb sin C
, La Lb , .
2

Lc, Lc2=La2+Lb2 -2LaLbcosC , sinA/sinC=La/Lc. .


:

27.

a) Y=k2X+b2, (X0,Y0)

Y=k1X+b1

b) (X1,Y1) ,
c) , (X1,Y1),
(X0,Y0) (X2,Y2) Y .
,
k1=1, b1=1, X0=0, Y0=2.

28.
2

AX +BY +CX+DY+E=0.

A1X2+B1Y2+C1X+D1Y+E1=0,
X1, Y1 .
.

. . , . . C VS C++

50

1. ?

2. ?
3. ?
4. ?
5.
?
6. ?
7. (, )?
8. ?
9. ?
10. printf?
11. ?
12. ?
13. , ,
printf?
14. printf?
15. scanf?
16. scanf?
17. ?

. . , . . C VS C++

51

3.
3.1

, ,
, , .
1: if, switch ( ) ?. - if else if else.
if
, ( ), ( ). ,
, , .


if else

if

O1

else

O2

W , (true ),
(false 0).
1 2 , ; ( ), .
( ;).


. . , . . C VS C++

52
if else W
, 1, ,
, 2.
if else
(

if

O1

W , 1 , ; ( ),
. if W , 1,
.
.
: > < , , =, , ,
==, <=, >=, != . .
. , Y
A, B, X, Y

:
if (A > B)
if

(B >= 3)
Y=2;

else

. . , . . C VS C++

53
;
else
Y=X;
if else Y=X;
if else, , , ( else)
Y=2;. else : else if, else. else
,
, {if

(B >= 3)

Y=2 }:

if (A > B)
{
if

(B >= 3)
Y=2;

}
else
Y=X;
. :

if else
if

(A<=B)
Y=X;

else
if

(B>=3)
Y=2;

. . , . . C VS C++

54


:
( ), ! ( ),
( ), &&,
( ),
||,
, .
!()
() ( X ); &

(X&Y XY X Y ); V (X V Y ).
.
X

!X

X && Y

X || Y

( , , ) , .
, . . ,
, .
. Y
Y=

A, ( A B > 1) & ( A > 0),

B, ( A + B > 1) & ( A < 0),


Y

. . , . . C VS C++

55
,
, ,
if else ( if), :
if (A*B>1 && A>0)
Y=A;
else
if (A+B>1 && A<0)
Y=B;
, (, , , ).

( )

W1

W2

W ,
W1 , , W (true),
W2 , , W (false).
W1,
W , W2.
if else .
- ,
, , printf("%f", x>0 ? sin(x) : 0); x>0
sin(x), x<=0 - 0.
- W1 W2 (,
), .

3.2.
1. Y(X),
( ||>3)
. . , . . C VS C++

56
Y
1
-3

-2

-1

-1

, ,
Z (1 | X|), 0 X 1,
Z,
1 < X < 2,
Y(X) =
Z,
2 X < 3,
, ,
Z=-1, X<0; Z=0, X=0; Z=1, X>0

:
if else, (!, &&, ||),
if else .
.
#include "stdafx.h"
#include "math.h"
char* Ruc(char s[])
{ // .
// .
int i;
static char ss[256];
for (i=0;s[i] != '\0'; i++)
{
if (s[i]>= -64 && s[i] <= -17)
ss[i]=(-64+s[i]); //..
else if (s[i]>= -16 && s[i] <= 0)
ss[i]=(char)(-16+s[i]); //..
else if (s[i] == -72)
ss[i]=(char)(-15); //
else if (s[i] == -88)
ss[i]=(char)(-16); //
. . , . . C VS C++

57
else
ss[i]=s[i];
}
ss[i]='\0';
return ss;
}
int _tmain(int argc, _TCHAR* argv[])
{

float x=-2;
float X=-0.3,A,Z,Y;//21.0001
printf(Ruc(" : "));
scanf("%f",&X);
//
A=fabs(X);
// Z
if (X>0)

Z=1.0;

else if (X==0)

Z=0.0;

else

Z=-1.0;

// Y
if (A>=3)
printf(Ruc(" . \n"));
else
{
if (A<=1.0)
Y=Z*(1-A);
else if (A<2.0)
Y=Z;
else
Y=-Z;
printf("Y = %f\n",Y);
}
// Y
if (A>=3)
printf(Ruc(" . \n"));
if (A<=1)
printf("Y = %f\n",Z*(1-A));
. . , . . C VS C++

58
if (A>1 && A<2)
printf("Y = %f\n",Z);
if (A>=2 && A<3)
printf("Y = %f\n",-Z);
return 0;
}
Y

2. Z
2

(. ), (X,Y),
:

a) if else Z1,

b) if else Z2.
, 1
R=5, . , ,
.
, Y Z1 Z2.
#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])


{
const float R=5.0;
float
int

X,Y;
Z1,Z2;

//
printf("X, Y: ");
scanf("%f %f",&X, &Y);
// Z1 - ,

// , .
//
// X,

if (Y<=0.0) //
Z1=4;

// Z1 4,

. . , . . C VS C++

59
// (

else

//),

// Y X,

if (Y<=X)

Z1=4; // Z1 4,

// ( 4),

else

if (Y<-X)

// ,

// 2 3,

Z1=3; // Z1 3,
// (

else

// , 2 3),
if (X<0)
Z1=2;

// <0,

//Z1 2,

// (

else

//),

if (X*X+Y*Y <= R*R) //

// X>0 R,

Z1=1; // 1,

else // (
// R),
//

Z1=2; // 2.
printf("Z1 = %d\n", Z1);
// Z2 - ,
// ,

// .

if (Y<=0 || Y<=X) // 4,
Z2=4; // Z2 4,

else // ( 4),

if (Y<-X) // 3,
Z2=3; // Z2 3,

else // ( 3 4),
if (X*X+Y*Y <= R*R && X>0) //

// 1,

. . , . . C VS C++

60
Z2=1; // Z2 1,

else // (
// 1, 3 4),

Z2=2; // Z2 2.
printf("Z2 = %d\n", Z2);
return 0;
}

3.3.
1 25 Y(X), , X:
Y1 = Y(X) if else, ,
Y2 = Y(X) if else,
,
Y1 Y2.
, , .
(. 3.2):
-

, -

,
-

29. Y ( X ) =

30. Y ( X ) =

1
X < 2,
X /2
2 X < 0,
X = 0,
2 .

0 1 > X ,
1 1 X < 0,
1 0 X < 2 ,
1 2 X.

. . , . . C VS C++

61
0 > X + X 2 > 0, 2

X
31. Y ( X ) =

32. Y ( X ) =

X 2 0 < X + X 2,
.
1 1 > X ,
0 1 X < 0,
1 0 X < 1 ,
0 1 X .

33. Y ( X ) =

1 2 > X ,
X + 1 2 X < 0 ,
1
0 X < 1 ,
0
1 X .

34. Y ( X ) =

0
1
0
1

35. Y ( X ) =

X < 2,
2 X < 1,
1 X < 0,
0 X .

0
X < 1 ,
X + 1 1 X < 0,
X
0 X < 1,
0
1 X .
1

X < 1,
X 1 X < 1,
36. Y ( X ) =
X + 2 1 X < 2 ,
0
2 X .

37. Y ( X ) =

38. Y ( X ) =

1 / X
X < 3,
X 3 X < 0,
2
X
0 X < 1 ,
X
1 X .
2 X
0
X
1 X

X 0,
0 < X < 1,
1 X < 3 ,
3 X .

. . , . . C VS C++

62
Y(X)
-2

39.

-1

-1

Y(X)
1

40.

-2
-3

-1

Y(X)

41.

-2

-1

42.

R=1
1

43.

Y(X)
2

-2
-1

Y(X)
1

44.

-2

-1

45.

. . , . . C VS C++

63
Y(X)
1

46.

-3

-4

-2

-1

-1

Y(X)
1
-4

47.

-3

-2

-1

-1

48. Y ( X ) =

0, |X| < 3 ,
1 , X 2 ,
1, X 2 ,

,
2

Y(X)

49.

-3

-2

-1

-1

50.

51.

. . , . . C VS C++

64
Y(X)
2
1

52.

-3

-2

-1

-1
-2

Y(X)

53.

-3

-2

1
1

-1

-1

26 30 ,
, X Y:
Z1 if else, ,
Z2 if else, .
Z1 Z2.
, , .

54.
-3

-2

Y
2
1
1

-1
-1
-2

IV

. . , . . C VS C++

65

55.

-3

56.

60o
-2

2
1

-1

IV

60o
2

-1

-2

Y
2

30o
30o

1
-3

57.

-2

-1

-1

IV

-2

IV

58.

-3
-2

-1

-2

-1

IV

. . , . . C VS C++

66

1. ?
2. if \ else if else
if else?
3. if else, if else,
else if?
4. ?
5. ?
6. ?
7. ?

. . , . . C VS C++

67

4.
4.1.
, , , . ( - ):
( for),
( while),
( do while).
,
, - ,
. , .

(for)
for
for

:
1 ,
- , W . ,
.
W , ,
( ), ,
(). ,
, , break (. ).
2 , . , ,
, .
- , ,
, , .
. . , . . C VS C++

68

,
#include "stdafx.h"
#include "math.h"

int _tmain(int argc, _TCHAR* argv[])


{
int i;
for (i=0; i<=6; i++)
printf("%10d%8.2f\n",i*10,sin(3.14/18*i));
return 0;
}
printf 7
i, 0 6 1.
, 0,
10, 20, , 60, , :
0

0.00

10

0.17

20

0.34

30

0.50

40

0.64

. . , . . C VS C++

69
50

0.77

60

0.87

for ,
1 2 ,
int i;
float r;
. . .
for (i=1, r=-1.0; i<=6; ++i, r/=-i)
printf("%10d%8.4f\n",i,r);

1 -1.0000
2

0.5000

3 -0.1667
4

0.0417

5 -0.0083
6

0.0014

i , , r
, i, .
for
( ) ,
.
, , .
, , , ,
, , .

int i;
float r;
. . .
r=-1.0;
for (i=1; i<=6; ++i)
{
. . , . . C VS C++

70
printf("%10d%8.4f\n",i,r);
r/=-i-1;
}
,
, for. ,
for (i=1; fabs(r)>0.0013; ++i)

(while)
while
(

while

:
W ,
O - , .
, , : ,
W (),
, ().
,
i=0;
while (i<=60)
{
printf("%10d%8.2f\n",i,sin(3.14/180*i));
i=i+10;
}
, for.

(do while)
do while
do

while

. . , . . C VS C++

71
, ,
W
().. , , for, :
i=0;
do
{
printf("%10d%8.2f\n",i,sin(3.14/180*i));
i=i+10;
}
while (i<=60);
,
, goto
( ), break.

continue. ,
( for ),
, .
- break continue
. . .
#include "conio.h"
. . .
int d,i;
. . .
d=0;
for (i=1; i<=3; ++i)
{
printf(Ruc("\n : "));

if (getch() != 'a') //getch #include "conio.h"


continue;
printf(Ruc("\n : "));
if (getch() == 'b')
{
. . , . . C VS C++

72
d=1;
break;
}
}

if (!d)
{
printf(Ruc("\n! .\n"));
return 0;
}
printf(Ruc("\n . \n"));
. . . //

(Debug\Start Without Debugging).


getch(),

#include

"conio.h".
. continue . , ,
.
( d
0), !
. .
d
1, break .

4.2.


.

. . , . . C VS C++

73
, . , for, while do while.
,
, ,
. , - :
1)
float X,H,Xk;// float
. . .
X=0.0;
H=1.0/3.0;
Xk=5.0/3.0;;//==1.6(6)
while (X<=Xk)
{
printf("\n%6.2f %8.2f", X,sin(X));
X=X+H;
}
:
0.00

0.00

0.33

0.33

0.67

0.62

1.00

0.84

1.33

0.97

2)
H=1.0/3.0;
X=-H;
Xk=5.0/3.0;
do
{
X=X+H;
printf("\n%6.2f %8.2f", X,sin(X));
}while (X!=Xk);
. . , . . C VS C++

74

, , 0 5/3 1/3.
5/3 sin(5/3),
5/3, .

< () / > () ,
. ,
1)
float X,H,Xk;// float
. . .
X=0.0;
H=1.0/3.0;
Xk=5.0/3.0+H/2.0;
while (X<Xk) // =5.0/3.0 .
{
printf("\n%6.2f %8.2f", X,sin(X));
X=X+H;
}
:
0.00

0.00

0.33

0.33

0.67

0.62

1.00

0.84

1.33

0.97

1.67

1.00

2)
H=1.0/3.0;
X=-H;
// H/2.0
. . , . . C VS C++

75
//
Xk=5.0/3.0-H/2.0;
do
{
X=X+H;
printf("\n%6.2f %8.2f", X,sin(X));
}while (X<Xk);// ,

// , 5.0/3.0, Xk.

, for . , ,
X1 X 0
N =
+ 1 ,
H

N ,
X0 X1 ,
H ,
c ] [ .
, 0,5 ceil ( ,
), 0,5
floor ( , ).

, .
0=0, 1=5/3 H=1/3, for
float X,H,Xk;// float

float x[6], y[6];//


//

int i,N;
. . .
. . , . . C VS C++

76
H=1.0/3.0;
//
N=ceil(5.0/3.0/H-0.5)+1;// ,

//N=floor(5.0/3.0/H+0.5)+1;//
for (i=0;i<N;i++)
{
X=i*H;
x[i]=X;
y[i]=sin(X);
printf("\n%6.2f %8.2f", X,y[i]);
}

4.3. while
/
,
2

e X
sin(10 X )
Y(X ) =
X

X (e X 10 cos(10 X ) 2 Xe X sin(10 X )) e X sin(10 X )


Y '(X ) =
X2

40o 50o 1o.


Y
, Y ' ( X )

Y ( X + X / 2) Y ( X X / 2)
X

X=10-8.
. .
, 40o 50o
1o, A, B H, :
A - , B - X, H - X. .
#include "stdafx.h"
. . , . . C VS C++

77
#include "math.h"
int _tmain(int argc, _TCHAR* argv[])
{
const double Pi=3.14;
//

double H=1;

//

double A=40;

//

double B=50;
double

int

F1,X,Y,P,P1,C,D,E,S;

I;

// A, B H,
// printf scanf
printf("Enter A, B, H:");
scanf("%lf%lf%lf",&A,&B,&H);
//
A=Pi*A/180;
H=Pi*H/180;
B=Pi*B/180+H/2;
// .
printf("\n

#
P1

Y(X)

P\

F1");

X=A;// X
//

I=0;// I
while (X<B)
{
//
I=I+1;
//
C=X*X; D=10*X; E=exp(-C); S=sin(D);
//: Y -
//

P -

// .
Y=E*S/X;
P= E*(D*cos(D)-S*(1+2*C))/C;
. . , . . C VS C++

78
// P1 -
//
// .

P1=((exp(-X*X)*10.0*cos(10*X)
-2*X*exp(-X*X)*sin(10*X))*X
-exp(-X*X)*sin(10*X))/X/X;
// F1 -
// .

F1=( exp(-(X+5E-9)*(X+5E-9))*sin(10*(X+5E-9))/(X+5E-9)

-exp(-(X-5E-9)*(X-5E-9))*sin(10*(X-5E-9))/(X-5E-9)
)/1E-8;
//
printf("\n%3d%8.2lf%10.5lf%11.5lf%16.10lf%16.10lf"
,I,X*180/Pi,Y,P,P1,F1 );
X=X+H;

//

}//while
printf("\n");
return 0;
}

printf ,
\. , , , , ,
P1 F1.
.
Enter A, B, H:40 50 1

Y(X)

P1

F1

40.00

0.56371

5.17198

5.1719834346

5.1719833971

41.00

0.64022

3.60082

3.6008211921

3.6008211635

42.00

0.68954

2.06375

2.0637549307

2.0637549114

43.00

0.71268

0.60541

0.6054120938

0.6054120871

44.00

0.71134

-0.73589

-0.7358908651

-0.7358908483

45.00

0.68787

-1.92882

-1.9288233230

-1.9288233011

. . , . . C VS C++

79
7

46.00

0.64505

-2.94945

-2.9494455353

-2.9494455323

47.00

0.58606

-3.78135

-3.7813491750

-3.7813491449

48.00

0.51428

-4.41555

-4.4155472441

-4.4155472168

10

49.00

0.43317

-4.85013

-4.8501348030

-4.8501347771

11

50.00

0.34620

-5.08975

-5.0897482960

-5.0897481951

, 7- .. 8- , . ,
, .

4.4. for
F ( X ) =

2 X ( X 1) ( X 2 1) ln( X 2 1)
( X 2 1)( X 1) 2

9 DX =(0,5; 0,25; 0,125;...)


:
1)
ln(( X + DX ) 2 1) ln( X 2 1)
,
DP( X ) =

( X + DX ) 1
X 1

2) F(X+DX/2)DX -
) DP1, ,
) DP2, ,
3) |DP-DP1| - .
DX
. , .
#include "stdafx.h"
#include "math.h"
int _tmain(int argc, _TCHAR* argv[])
{
const double X=1.5;
double

DP,DP1,DP2,D,R,K,X1,DX;

. . , . . C VS C++

80
int I,N;
//
printf("%s%s"
,"

DX

,"DP1

DP
DP2

"

|DP-DP1|");

// DX
//

DX=0.5;
for (I=1;I<10;I++)
{
// DP(X)
DP=log((X+DX)*(X+DX)-1)/(X+DX-1)-log(X*X-1)/(X-1);
//
X1=X+DX/2; K=X1*X1; R=K-1; D=X1-1;
// DP(X)

//
DP1=(2 * X1 * D - R * log(R)) / R / D*D*DX;
//
DP2=(2*(X+DX/2)*(X+DX/2-1)-((X+DX/2)*(X+DX/2)-1)
*log((X+DX/2)*(X+DX/2)-1))
/((X+DX/2)*(X+DX/2)-1)/(X+DX/2-1)/(X+DX/2-1)*DX;
//
printf("\n%3d%10.5lf

%12.6lf %10.6lf %9.6lf

%e"

,I,DX,DP,DP1,DP2,fabs(DP-DP2));
//
DX=DX/2;
}// for
printf("\n");
return 0;
}
.
#

DX

0.50000

DP
0.652325

DP1

DP2

|DP-DP1|

0.274404

0.487830

1.644955e-001

. . , . . C VS C++

81
2

0.25000

0.518938

0.185754

0.475532

4.340651e-002

0.12500

0.345837

0.106737

0.337340

8.496082e-003

0.06250

0.203703

0.057105

0.202339

1.363851e-003

0.03125

0.111248

0.029526

0.111054

1.947223e-004

0.01563

0.058238

0.015011

0.058212

2.607041e-005

0.00781

0.029810

0.007568

0.029806

3.374592e-006

0.00391

0.015082

0.003800

0.015082

4.293168e-007

0.00195

0.007586

0.001904

0.007586

5.414117e-008

, ,
%s .
, , .

4.5.
.
1.

20

X =

1
2
3
, 1 , 1 ,...
2
3
4

:
ln(1+x),

X2 X3 X4 X5
+

+
2
3
4
5

/ ,
, ,
.
for. , , , .
2.

X=(-0,5; -0,25; 0; 0,25; 0,5; 0,75; 1) -

:
X
e ,

. . , . . C VS C++

82

1+ X +

X2 X3 X4 X5
+
+
+
2!
3!
4!
5!

/ ,
, ,
.
while. , , ,
.
3.

X, 0,1 /3 0,05,

:
sin(x),

X3 X5 X7 X9
+

+
3!
5!
7!
9!

/ ,
, ,
.
for. , , ,
4.

do while X, 0 /4

0,1, :
cos(x),

X2 X4 X6 X8
+

+
2!
4!
6!
8!

/ ,
, ,
.
. . , . . C VS C++

83
, , , .
5.

X, A B H,

:
tg(x),

X+

X 3 2 X 5 17 X 7 62 X 9
+
+
+
3
15
315
2835

/ ,
, ,
.
for. , , , .
6.

M, 0 6 0,5,

:
M
(1 + X ) ,


1+ M X +

M ( M 1) X 2 M ( M 1)( M 2) X 3 M ( M 1)( M 2)( M 3) X 4


+
+
2!
3!
4!

/ ,
, ,
.
while. , , ,
.
7.

X=(1; 0,5; 0,25; 0,125; 0,0625; 0,03125; 0,015625)

:
1 + X ,

. . , . . C VS C++

84

1+

3X 3
35X 4
X X2

2 2 4 2 4 6 2 4 6 8

/ ,
, ,
.
for. , , , .
X=sin(5o), sin(10o),, sin(60o)

8.
:

arcsin(x)

X+

X3
3X 5
3 5X 7
357X 9

23 2 45 2 467 2 4689

/ ,
, ,
.
for. , , , /
9.

do whil 15

1
1
1
X = tg ( 45 ), tg ( 45 ), tg ( 45 ),... :
2
3
4
arctg(x)
-

X3 X5 X7 X9
X
+

+
3
5
7
9

/ ,
-

,
-

. . , . . C VS C++

85
-

, , , .
10. X, X0 X1 H,
:
e X eX
2


X3 X5 X7 X9
X+
+
+
+
3!
5!
7!
9!

/ ,
-

,
-

for. , , , .
2

Xe X
11. Y =
X :
1+ X
2

e X ((1 2 X 2 ) (1 + X ) X )
Y ' =
(1 + X ) 2

) ,
) ,
-

8- DX=(0,2; 0,04; 0,008;):

DY=Y(X+DX)-Y(X),

DY/DX,

while.
DX .
12. Y =
-

1+ 2X
X :
X 2 1

Y ' =

2( X 2 1) 2 X (1 + 2 X )
( X 2 1) 2

) ,
) ,
. . , . . C VS C++

86
-

DX=(0,0001; 0,001; 0,01; 0,1):

DY=Y(X+DX/2)-

Y(X-DX/2),
-

DY/DX,

for. DX .
13. Y =

Y'=

ln(1 + cos X )
X :
2X +1

sin X
ln(1 + cos X ) 2 X ln 2

(1 + cos X ) (2 X + 1)
(2 X + 1) 2

) ,
) ,
-

DX=(10-2, 10-3, 10-4, 10-5, 10-6):

DY=Y(X+DX)-Y(X),

DY/DX,

for. DX .
14. Y =

Y'=

2X
X
1 + ln(2 + cos( X ))

2 X ln 2 (1 + ln(2 + cos X )) +

(1 + ln(2 + cos X )) 2

2 X sin X
2 + cos X

) ,

) ,
-

do while DX=(0,00001;

0,0001; 0,001; 0,01; 0,1):


-

DY=Y(X+DX/2)-

Y(X- DX/2),
-

DY/DX,

. . , . . C VS C++

87
DX

.
15. Y = ln(1 + X 2 )tg ( X 2 ) X=0,3 :

Y '=

2 X tgX 2 2 X ln(1 + X 2 )
+
cos 2 X 2
1+ X 2

) ,
) ,
for DX=(0,00000025;

0,000005; 0,0001; 0,002; 0,04; 0,8):


-

DY=Y(X+DX)-Y(X),

DY/DX,

DX

.
16. Y =

Y'=

sin X
X :
ln(2 + sin 2 X )

2 sin 2 X cos X
2 + sin 2 X
ln 2 (2 + sin 2 X )

cos X ln(2 + sin 2 X )

) ,
) ,
-

while DX=(0,0005; 0,001;

0,002; 0,004; 0,008; 0,016):


-

DY=Y(X+DX/2)-

Y(X- DX/2),
-

DY/DX,

DX

.
17. Y = arctg (

X +1
) X :
1 X

. . , . . C VS C++

88
-

Y ' =

1
1+ X 1+ X
)
(1 X ) 2 (1 +
1 X 1 X

) ,
) ,
-

for DX=(0,000001;

0,000004; 0,000016; 0,00--64;):


-

DY=Y(X+DX)-Y(X),

DY/DX,

DX

.
18. Y =
-

X +1
X :
( X + 2)( X + 3)

Y ' =

1 ( X + 2) X
( X + 2) 2 ( X + 3) 2

) ,
) ,
-

for 12- DX=(1/3, 1/9,

1/27, 1/81,):
-

DY=Y(X+DX)-Y(X),

DY/DX,

DX

.
19.
/ ,
Y(X ) =

do

while

tg 4 X tg 2 X

ln(cos 2 X )
4
2


tg 3 X
tgX
Y '(X ) =

2tgX
2
cos X cos 2 X

-7,5o 7,5o 0,75o.


. . , . . C VS C++

89

.
.
20.
/ ,
( X 1) ( X 1) 2 ( X 1) 4
Y(X ) = (

+
)( X 2 1)
2
2
3

1
4( X 1)3
( X 1) (1 X ) 2 (1 X ) 4

+
Y ' ( X ) = ( ( X 1) +
)( X 2 1) + (
)2 X
2
3
2
2
3

-1,1 1,0 0,1.



.
. for.
21. F ( X ) =

2 X (1 X ) + (1 + X 2 ) 1 X
X= 0,5 K 2(1 X ) 2
1+ X 2

DX=(0,0005; 0,001; 0,002; 0,004; 0,008;...) :


DP =

1 + ( X + DX ) 2
1+ X 2
,

1 ( X + DX )
1 X
-

(F(X+DX/2)DX - -

:
) ,
) ,
-

.
DX . while.

. . , . . C VS C++

90
e X eX
22. F ( X ) = X
X N e + eX

DX=(-0,1; -0,1/4; -0,1/16;) :
-

DP = ln(e X + DX + e ( X + DX ) ) ln(e X + e X ) ,
-

F(X)DX - -

) ,
) ,
-

.
DX
. for.

sin 3 X + 1
X
23. F ( X ) =
sin 2 X

DX=(-0,0005; +0,001; -0,002; +0,004; -0,008; +0,016) :


-

DP = cos( X + DX ) ctg ( X + DX ) + cos X + ctgX ,

F ( X + DX ) + F ( X )
DX - 2


) ,
) ,
-

.
DX
. for.

. . , . . C VS C++

91
24. F ( X ) =

2 Xe X
1 + e X

X K -


DX=(-0,0005; -0,001; -0,002; -0,004; ) do while:
-

DP = ln(1 + e ( X + DX ) ) ln(1 + e X ) ,
-

F(X+DX/2)DX -

) ,
) ,
-

.
DX
.
2

25. F ( X ) =
(2 X 1)

1
)2
1 (
2 X 1

X=1,5 K

DX=(510-1; 510-2; 510-3; 510-4;) :


DP = arccos(


1
1
) arccos(
),
2( X + DX ) 1
2X 1

F(X)DX - -

) ,
) ,
-

.
DX
. for.

. . , . . C VS C++

92
26. F ( X ) =

2X
X K ( X 1) 2 + 1
2

DX=(0,1; -0,05; 0,025; -0,0125;...) :


-

DP = arctg (

1
1
) arctg ( 2 ) ,
2
( X + DX ) 1
X 1

F ( X + DX ) + F ( X )
DX - 2


) ,
) ,
-

.
DX
. while.
27. F ( X ) = cos X

1
X K cos 2 X

DX=(0,08; 0,04; 0,02; ) :


-

DP = (sin( X + DX ) tg ( X + DX )) (sin X tgX ) ,


-

F(X+DX/2)DX -

) ,
) ,
-

.
DX
. for.

. . , . . C VS C++

93
1

28. F ( X ) =
( X 1)

1 2
)
1 (
X 1

X=10 12

DX=(1/4, 1/6,1/8,...) :
-

DP=arcsin(1/(X+DX -1))-arcsin(1/(X-1)),
-

F(X)DX - -

) ,
) ,
-

.
DX
. for.
29. F ( X ) =

X
X 2 +1

X=0,95

DX=(0,0005; 0,001; 0,002; 0,04; 0,08; 0,016; 0,032) do while:


-

DP = ( X + DX ) 2 + 1 X 2 + 1 ,

F ( X + DX ) + F ( X )
DX - 2


) ,
) ,
-

.
DX
.
30.
/ ,

. . , . . C VS C++

94
Y(X ) =

Y '(X ) =

aX

2 1

+ a X 1
X 1

(2 Xa X

2 1

+ a X 1 ) ln(a)( X 1) (a X
( X 1) 2

2 1

+ a X 1 )

1 3 7
2 20 1
20- X = ( , , , ..., 20 ) .
2 4 8
2
Y' .

.
for.

. . , . . C VS C++

95

4.6.
, . , , ,
.
, , (,
). .
( , ) ,
. 0, .

, ,
, . ,
float X[3], Z[3];
X Z , X[0], X[1], X[2] Z[0], Z[1], Z[2].
, , (
), ,
. ,
double Y[10]={ 1.2, 4.2, -5.1, 4.4, -1.5};
:
Y[0] = 1.2, Y[1] = 4.2, Y[2] = -5.1, Y[3] = 4.4, Y[4] = -1.5.
,
, . , , , - .
. . , . . C VS C++

96
, , , .
,
, , , . Y, - , , , double.
, :
(20) , , 20 .
(N), N<=20 ,
, N .
, .
. Y
y=sin x X - .
dX X0.

#include "stdafx.h"
#include "math.h"
int _tmain(int argc, _TCHAR* argv[])
{
const int n=10;
double X[n], Y[n], X0, dX, Pi;
int i;
printf("Enter X0 :");
scanf("%lf",&X0);
printf("Enter dX :");
. . , . . C VS C++

97
scanf("%lf",&dX);
Pi=atan(1.0)*4.0;
for (i=0; i<n; i++)
{
X[i]=X0;
Y[i]=sin(X0*Pi/180);
X0+=dX;
}
for (i=0; i<n; i++)
printf("%6.2lf %lf\n",X[i],Y[i]);

return 0;
}

4.7.
M(10) X(N), N500, 1
10 h=(Xmax-Xmin+1)/10, Xmax=50 Xmin=1 X . X Xmin Xmax, rand. srand, ,
srand - , (.
).
Xmin, Xmax h . :

. . , . . C VS C++

98
X
N

MX DX : MX =

Xi
i =1

DX =

( X i MX ) 2
i =1

#include "stdafx.h"
#include "time.h"

// time

#include "stdlib.h"// srand rand


int _tmain(int argc, _TCHAR* argv[])
{
const unsigned Nmax=500, Xmax=50, Xmin=1, h=5;
unsigned M[10], X[Nmax], t;
unsigned i, j, u, N;//N -
float MX, DX;
//
printf("Enter N:");
scanf("%u", &N);
// ,

t=time( NULL ); // 1.1.1970


//

srand(t);//
// N

// Xmin Xmax X

//(RAND_MAX - )
for (i=0; i<N; i++)
X[i]= (double)rand()/(RAND_MAX + 1)
* (Xmax - Xmin+1)+ Xmin;
// M

// X
//[0..4], [5..9], , [45..49]
for (i=0; i<10; i++) M[i]=0;
for (i=0; i<N; i++)
. . , . . C VS C++

99
// 1 M

M[(X[i]-Xmin)/h]++;// (X[i]-Xmin)/h
//
for (i=0;i<10;i++)
{
printf("%3d - %3d%3d ",i*h+1,(i+1)*h,M[i]);
for (j=0;j<M[i]; j++)
printf("X");
printf("\n");
}
//
MX=0;
for (i=0; i<N; i++)
MX=MX+X[i];
MX=(float)MX/N;
printf("\nMX = %lf\n",MX);
//
DX=0;
for (i=0; i<N; i++)
DX=DX+(X[i]-MX)*(X[i]-MX);
DX=(float)DX/N;
printf("DX = %lf\n",DX);

return 0;
}

4.8.
.
10.

M(5) 1, 5, 10, 50, 100.

N K(5) N = K1M1+ K2M2+ K3M3+ K4M4+ K5M5,


5

K
i =1

( % / ).

. . , . . C VS C++

100
11.

(N), N20, 1 k,

k<N, S(k) - 1 k . :
S,
. i- M P.
12.

(N), N10,

,
.
13.

F 30 e-xsin(6x), .
14.

S L30.

Y , S, : Y0=S1, ,
.
Y .
15.

S (. )

Y Y .
16.

S L<30 -

D. : D1=S1, Di=1,
S i = S i 1 , 0. D R.
17.

X(4)

. K(4) R: R = D+K0X0+ K1X1+ K2X2+ K3X3, D<X0,


ki

i =1

18.

(N), N<=20, -

, Y ,
C,
19.

X H -

F 20 e X sin(6 X )
.
. . , . . C VS C++

101
20.

V(10), ,

0 9 . D S L30 0 9. : Di = i VS . D i

k- R.
21.

N n0, n1, n2, n3, n4, n5 -

K (0<K<106) 10.
22.

(N), N20, K -

, K , K . D.
23.

X(20) e-xsin(3x)-0,2,
, .
, .
24.

(N), N20, ,

, .
25.

S 1, 2, 3 4 L20.

K N , S, : Ki i-
S, Ni , K N .
26.

, , -

Y , .
27.

X Y, -

.
28.

(N), N20, , K, -

, .
.
29.

K(N), N14, N

R , D -
R, 10-N. floor ceil.

. . , . . C VS C++

102
30.

X(50) e 3 x sin 2 20 x ,
, Y . 50 , , X Y
.
31.

(20),

Y ,
P , .
32.

X(12) e x / 3 sin 2 5 x ,
. , .
33.

X Y ,

, R.
34.

K 0 9, , -

0 9 .
Y X L30 0
9. : Yi = i K X .
i

Y P. T , : Ti
K i.

1. ?
2. ( ) for?
3. for ?
4. while?
5. do while?
6. ?

7. ?
. . , . . C VS C++

103
8. ?

. . , . . C VS C++

104

1. . ., . . , 2- ,: . .
.:. , 2006. 304 .: .
2. . - C++.
Computer Science. 4- . .: , 2008. -928 .: .
3. .. /++. .
:, 2007.-461 .: .
4. .. C/C++ MS Visual C++ 2008 . : , 2008.- 624 .: .

. . , . . C VS C++