.


:




:

































 

 

 

 


/




 

/ ++ (streams). / , . / . , , , , , .

/ ++. / , , , , / . , , , , .

++ , :

 

/
cin
cout
cerr
clog cerr

 

cin, cout.

/ iostream. / ++ : << >>.

<< ++. .

 

cout << .\n

 

cout << 100.99;

 

, >>. , num.

 

int num.

cin >> num;

 

/.

 

2

/* ,

*/

 

#include <iostream.h> //

// /

 

void main(void)

{

int i, j; //

double d; // i, j, d

i = 10; //

j = 20; //

d = 99.101; //

 

//

cout << : ;

cout << i;

cout << ;

cout << j;

cout << ;

cout << d

}

 

 

.

 

: 10 20 99.101

 

/ . , 2 :

 

3

/* ,

*/

 

#include <iostream.h> //

// /

 

void main(void)

{

int i, j; //

double d; // i, j, d

i = 10; //

j = 20; //

d = 99.101; //

 

//

cout << : << i << << j << << d;

}

 

 

, .

4 , .

 

 

4

/*, */

 

#include <iostream.h> //

// /

 

void main(void)

{

int i; //

cout << : ;

cin >> i;

cout << : << i << \n;

}

 

 

. printf(). printf() ++, #include -, printf(). stdio.h.

printf() (. 1) .

 

:

int printf(const char * format [, argument ] ... );

:

.

:

format ;

argument .

:

, .

-:

stdio.h

:

 

printf(One string);

:

One string

 

printf(%s %s, One, string);

:

One string

 

printf(%s\n%s, Two, string);

:

Two

string

 

printf([%d: %d], 1, 0);

:

[1: 0]

 

: , , , , . % - .

:

% [] [] [. ] [{ h | l | I64 | L }]

 

1.2 . :

%

 

- 1. % -, .

 

1. printf

;
d, i int;
o unsigned int; ( 0 )
x, X unsigned int; ( 0x 0X ), 10 15 abcdef x ABCDEF X
u unsigned int;
c int; unsigned char
s char *; , '\0' ,
f double; [-]mmm.ddd, d . 6;
e, E double; [-]m.ddddddexx [-]m.ddddddExx, d . 6;
g, G double; %e %E, -4 ; %f.
p void *; (
n int *; , printf, .
% ; %

 

. - d, g s.

,
d printf(%d, 5);
g ( ) printf(%g, 5.00);
s printf(%s, fine!);

 

printf():

 

printf(I am %s\n %d: %d\n, fine!, 1, 0);

 

:

 

I am fine!

1: 0

 

I am. , %, - . %s. , fine!. , \n - . , . 2 .

 

2.

\n
\t
\
\
\\
\?

 

, \n . %d: %d. , ( 1 0) , :. \n.

 

 

. , . , , , .

++ : srand() rand() stdlib.

. srand() .

rand() 0 RAND_MAX. . 5 .

 

5

/*

srand ()*/

 

#include <iostream.h> //

// /

# include <stdlib.h> //

// srand() rand()

 

void main(void)

{

srand (2); //

//

cout << rand() << \n;

cout << rand() << \n;

}

 

 

, ( 5) . , srand(2). , srand() . , , . 6 .

 

6

/*

srand ()*/

 

#include <iostream.h> //

// /

# include <stdlib.h> //

// srand() rand()

# include <time.h> //

//

void main(void)

{

srand ((unsigned) time(NULL)); //

//

cout << rand() << \n;

cout << rand() << \n;

}

 

 

.

 

 


 

, :

 

7

/* printf()*/

 

#include <stdio.h>

void main(void)

{

printf(I love \ Algorithmization and programming!\\n);

}

 

 

8

/* <<*/

 

#include <iostream.h>

void main(void)

{

cout << I love\n;

cout << \Algorithmization and programming!\n);

}

 

 

9

/* printf()

: , ,

*/

 

#include <stdio.h>

void main(void)

{

printf(I am %s\nGroup: %s\nOrder number: %d\n, Ivanov Ivan, TA-0113, 1);

}

 

 

! 9, .

 

10

/*/ << >>

22,

*/

 

#include <iostream.h>

void main(void)

{

int a, b, c, d;

cout << "Input elements\n";

cin >> a >> b >> c >> d;

cout << Matrix 2x2\n;

cout << a << \t << b << \n;

cout << c << \t << d << \n;

}

 

 

:

 

Input elements

 

. Enter.

 

11

/* 10.

*/

 

#include <iostream.h>

# include <stdlib.h>

# include <time.h>

void main(void)

{

srand ((unsigned) time(NULL));

int a, b, c, d;

a = rand();

b = rand();

c = rand();

d = rand();

cout << Matrix 2x2\n;

cout << a << \t << b << \n;

cout << c << \t << d << \n;

}

 

 

. .


 

1) . ?

2) . , . ?

3) . . ?

4) / ?

5) ?

6) . ?

 


2

 

: ++.

 

:

1) , .

2) , .

3) , .

 

 





:


: 2016-11-18; !; : 690 |


:

:

, .
==> ...

1531 - | 1357 -


© 2015-2024 lektsii.org - -

: 0.067 .