.


:




:

































 

 

 

 


Device. put (char_var);, 2




 

20. 10 , .

 

21. ' , b, c .

ϳ:

 

22. ' R (, ).

ϳ: :

 

23. ' .

 

24. ϳ

, .

25.

i.

 


2 ’ C ̲ ̲ ²

 

2.1 ֳ

 

, .

 

2.2

 

, , , .

, , .

 

2.1 y = axi2 sin xi, x1=-1, x2=-0,93, x3=-0,49, x4=0, x5=1,13, x6=0,96, x7=1,75.

 

' ', . , ' (), . , . ' ' ', .

x[n] (n =7). . 0 n 1. , .

:

// P2_1.CPP -

//

#include <iostream>

 
 


 

a=10.5

 

i=0

 

y=axi*xi-sin(xi)

i=i+1

#include <math.h>

Using namespace std;

Void main()

{

const int n =7;

float x[n];

Int i;

Float a, y;

//

cout<< " :" <<endl;

for (i=0; i < n; i++)

{

cout << "x [" << i << "] = ";

cin >> x [ i ];

cout << x [ i ] << endl;

}

a = 10.5;

//

for (i = 0; i < n; i++)

{

y = a*x [ i ] * x [ i ] sin (x [ i ]); cout << " =" << x[i]

<< "y = " << y << endl;

}

}

float x [n], ' ', .

, , cin >> x [i];, cout << "x [" << i << "] = "; x[i], .

cin >> x[i]; , , , ' x[i] Enter, . , f or, n , .

++ , float x[7] (n =7) x[0], x[1], x[2] x[6] x[0] , x[1] .. : , . ֳ , :

 

// 2_2.CPP

//

#include < math.h>

#include < iostream>

Using namespace std;

Float a, y;

Void main ()

{

const int n =7;

float x [ n ];

Int i;

Float a, y;

a = 10.5;

for (i = 0; i < n; i++)

{

cout << "x [ " << i << "] = ";

cin >> x [ i ];

y = a * x[ i ]*x[ i ] - sin(x[ i ]);

cout << " =" << x[] << " y= " << y << endl;

}

}

2.2 10 , .

mas[i] (i=0..9), , , :

 

// 2_3.CPP

//

#include < math.h >

#include < iostream>

Using namespace std;

Void main ()

{

const int n = 10; //

float mas[n]; //

Int i, k;

Float s;

s = 0; // s -

k = 0; // k -

for (i=0; i < n; i++)

{

cout << " mas [ " << i << "] = ";

cin >> mas [ i ];

cout << mas [ i ] << endl;

s = s + mas [ i ];

if (mas[ i ] = = 5)

k =k+1;

}

cout << " = " << s / float(n) << endl;

cout << "ʳ =" << k<< endl;

}

 

s , k . .

cout << " mas [ " << i << "] = ";

, (cout << " "<< s / float (n) << endl; cout << "ʳ =" <<k<< endl;).

, , , . . , . , :

 

̳ , .

. , [1] [2] , , -20.5 ( 0). -, : , - .

 

2.3 M 10.

 

// 2_4.CPP

// 10.

 

#include < iostream>

Using namespace std;

Void main ()

{

const int n = 3; //

const int m = 5; //

float M [ n] [m];

Int i, k;

Float s;

s = 10;

cout << " :" << endl;

//

for (i = 0; i < n; i++)

for (k = 0; k < m; k ++)

{

cout << " M [ " << i << "] = " << "[ " << k << ]";

cin >> M [ i ] [ k ];

cout << M [ i ] [ k ] << endl;

M [ i ] [ k ] = M [ i ] [ k ] + s; // M [ i ] [ k ] + = s;

}

cout << " :" << endl;

//

for (i = 0; i < n; i++)

{

cout << endl;

for (k = 0; k < m; k++)

cout << M [ i ] [ k ] << " ";

}

}

float M[n][m];

, , .

, , . i k.

' , .

 

 

2.3

++ , .

, ', . , , (). ֳ : , , .. - , , ' .

:

* ';

, ;

' ' -;

* , "" .

:

int *pn; // ;

float *pf1, *pf2; // ;

' - - . NULL, "" .

++ , :

& " ";

* " ".

" * ", , , , .

" & ", , , .

:

<> *ptr;

<> *ptr = < - >;

<> *ptr =&<' >; //

:

int *ptx,b; float y; // - ptx b y;

float *sp = &y; // sp y

float *p = sp; // p ( ),

// sp, y.

" * " ' - , , :

long * pt; long* Uk; int * ki, x, h; //

, void, :

 

void *p, *pt; //

, ' - , , .

, , ' "*", :

 

int *p, *p1; // ' int;

int x =12, y=5, m [7 ]; // x,y m,

// x,y

p = &y; // p y.

, :

cout << " " << p << " = " <<*p;,

', y ( 5).

x = *p;, x=5, *p = y = 5;.

y :

y = 10; // *p = 10;

* p= * p+5; // y = y + 5; y = 15.

 

, (), ' (), ' (), 0 ( ),:

int *pt = (char *) 0x00147; //

int *arrpt = new int [10]; //

//

har *p = 0; //

, " * ", , :

 

float *pt1, *pt2, x=15, m[5];

pt1=&x;

pt2=pt1;

pt1 = m; // pt1 = &m[0]; m ' ,

// .

:

// P2_5.CPP

#include < iostream>

Using namespace std;

Int main ()

{

int x = 10;

int *px = &x;

cout << " x =" << x << endl;

cout << "*px =" << *px << endl;

x* = 2; // x = x*2;

cout << " * px =" << *px << endl;

*px += 2; // *px =*px + 2;

cout << " * px=, =" << x << endl;

Return 0;

}

:

x = 10

*px = 10

*px = 20

*px, x = 22

- ,

:

int *pt1, *pt2;

pt1 = (int*) &pt2; // pt1 ',

// pt2

, :

int y,*pt1, *pt2 =&y;

pt1 = (int*) & pt2;.

" & ":

( '), : vp = &345;

, : vp = & (x + y);.

 

:

;

;

;

.

, - :

 

// P2_6.CPP -

#include < iostream>

Using namespace std;

Void main (void)

{

int *ptr1 = (int*)100;

int *ptr2 = (int*) 200;

ptr1++;

ptr2 -= 10;

cout << "ptr1=" << ptr1 << endl;

cout << "ptr2=" << ptr2 << endl;

cout << "ptr2 - ptr1=" << ptr2 - ptr1 << endl;

}

:

ptr1 = 00000068

ptr2 = 000000A0

ptr2 - ptr1 = 14

ptr1++ 4 , int 4 , ptr2-=10 40 . .

 

2.4

 

++ ' . : int mas [20]; ' mas - () , &mas[0].

:

, , mas[2] mas[i];

, , *(mas +2) *(mas+i).

' -, :

 

int mas [20];

int *ptr1;

ptr1 = mas; // ptr1 = &mas[0];

ϳ int mas [20]; &mas[0] mas .

: int mas[10] = {0}; ' 0. , .

, float mas [10] ={ 12.2, 34.56 };, 0.

, .

:

< > < ' > [n] //

// n

< > < ' > [n] = { } //

< > < ' > [ ] = { } //

:

float m[6];

float m[6] = { 3.4, 4.5, 5.6, 6.7, 8.9, 10.3 };

float m[ ] = { 3.45, 4.56, 5.67, 6.78 };

, :

 

int mas [2][5] ={ 1, 2, 3, 4, 5,

10, 11, 13, 14, 25 };

int mas [2][5] ={ {1, 2, 3, 4, 5},

{10, 11, 13, 14, 25} };

int mas [ ][5] ={ 1, 2, 3, 4, 5,

10, 11, 13, 14, 25 };.

, .

. , .

' ', , mas[1] 1, p = &mas[0], p=p + 1 (p += 1) i p + i;. , , , :

[] = x[0] + *sizeof ();.

1 2 , : ==,!=, <, <=, >, >=.

, 1 < 2 , 1 , 2. .

, , , . " " . , , :





:


: 2015-11-05; !; : 534 |


:

:

- , - .
==> ...

1643 - | 1562 -


© 2015-2024 lektsii.org - -

: 0.151 .