C/++
, 2013
.. 4
1. . 4
1. . 4
1.1. .. 4
1.2. . 6
1.3. . 7
1.4. . 10
1.5. . 11
1.6. .. 12
1.7. . 12
1.8. . 13
2. .. 14
3. .. 14
4. . 16
2 . 18
1. . 18
1.1. . 18
1.2. . 18
1.3. .. 18
1.4. new delete. 18
2. .. 20
3. . 23
3 . 24
1. . 24
1.1. . 24
1.2. -. 25
1.3. . 26
2. .. 27
3. .. 28
4 . 32
1. . 32
1.1. . 32
1.2. . 33
2. .. 34
3. .. 34
5 C/C++. 38
1. . 38
1.1. . 38
1.2. . 39
2. .. 40
3. .. 40
6 . 45
1. . 45
1.1. C/C++. 45
1.2. -. 46
2. .. 47
3. .. 47
4. . 52
7 53
1. . 53
2. .. 54
3. .. 55
4. .. 55
5. . 57
.. 57
. .
:
.
(, , ) . ( main) .
.
( main) -, -.
. .
1.
|
|
: , , , / . .
C 1972 . Unix. . , , , : , for, while, if . ., , , : , , . .
C/C++ :
#
.........
#
()
()
void main () //,
‑ . ‑ . . #. :
1. #define ‑ .
#define ZERO 0.0 ‑ , ZERO 0.0. . const. .
2. #include< >
‑ , . C/C++ . . include , . , . . . , , .
. , . main. . ( ). , void: void main (). , main , , (void).
. ‑ , , . , .
|
|
- ( ‑ , - ), . :
int y = 10; //
float x; //
‑ , .
‑ .
‑ , . 5 :
;
;
;
;
(NULL).
. . , - . , . . . , , . :
__;
, | |||
unsigned char | 8 | 0.. 255 | |
char | 8 | -128.. 127 | |
enum | -32768.. 32767 | ||
unsigned int | 0.. 65535 | ||
short int (short) | -32768.. 32767 | ||
unsigned short | 0.. 65535 | ||
int | -32768.. 32767 | ||
unsigned long | 0.. 4294967295 | ||
long | -214748348.. 2147483647 | ||
float | 3.4-38.. 3.4+38 | ||
double | 1.7-308.. 1.7+308 | ||
long double | 3.4-4932.. 1.1+4932 |
. , :
_ = _;
. :
float pi = 3.14, cc=1.3456;
unsigned int year = 1999;
:
& | |
* | () |
- | , |
~ | ( ) |
! | (). 0 - 0 - , 0 1, 0. |
++ | : - , . |
- - | : - , . |
sizeof | ( ) , |
.
:
+ | ( ) |
- | ( ) |
:
* | |
/ | ( , ) |
% |
( ).
:
_ _ _
|
|
<< | , |
>> | , |
:
& | () |
| | () |
^ |
:
< | , |
> | , |
<= | |
>= | |
== | |
!= |
:
&& | () , (0) (1) |
|| | () , (0) (1) |
.
.
1? 2: 3;
1. , 2, . 1 0, 3.
:
x<0? -x: x; // x.
() .
: :
(_)
_ ()
.
() [ ] ->. | |
! ~ - ++ -- & * () sizeof () | |
* / % ( ) | |
+ - ( ) | |
<< >> ( ) | |
< > <= >= () | |
==!= () | |
& ( Ȼ) | |
^ ( Ȼ) | |
| ( Ȼ) | |
&& ( Ȼ) | |
|| ( Ȼ) | |
?: ( ) | |
= *= /= %= -= &= ^= |= <<= >>= ( ) | |
, ( ) |
, , . , , . , . : + - * / %.
- , . C/C++ , , , 0, .
C/C++ -
#include <stdio.h>
printf (< >,< >);
< > - , , , . :
printf ( %f\n, pi);
:
;
.
:
%d - ;
|
|
%f - ;
%c - ;
%s - .
\n - .
scanf (< >,< >);
. :
scanf( %d%f , &x, &y);
1.5.2. ++
iostream.h, cin cout, :
<< - ;
>> - .
:
#include <iostream.h>;
.........
cout << \n : ;
cin >> n;
. , . . :
{
n++;
summa+=n;
}
{
int n=0;
n++;
summa+=n;
}
- . .
if (<->) <>; //
<-> , . <-> (. . ), . :
if (x<y&&x<z)min=x;
if (<->) <1>; //
else <2>;
<-> , 1, <-> 2.:
if (d>=0)
{
x1=(-b-sqrt(d))/(2*a);
x2=(-b+sqrt(d))/(2*a);
cout<< \nx1=<<x1<<x2=<<x2;
}
else cout<<\n ;
.
switch (<>)
{
case <1>: <1 >;
case <2>: <2 >;
...........
default: <>;
switch, , switch , case. , case . , . , , . , switch , , default. default .
:
switch (number)
{
case 1: cout<< =1;break;
case 2: cout<< 2 * 2<<number * number;
case 3: cout<< 3 * 3<<number * number; break;
case 4: cout<< number<<- ; break;
default: cout<< ;
}
break. break, , case, , switch, default.
while (<->)
<_>;
<-> . , . . 0, <-> .
do
<_>;
while (<->);
, <-> .
for (<_1>;<->;<_3>)
<_;>
<_1> <_3> , . <_1> ‑ ().<-> , 0, , <_3>. <_3> ‑ (). , <-> 0. , ; .
|
|
.
:
for (n=10; n>0; n--)
{ < >};
:
for (n=2; n>60; n+=13)
{ < >};
, :
for (num=1;num*num*num<216; num++)
{ < >};
:
for (d=100.0; d<150.0;d*=1.1)
{ < >};
for (x=1;y<=75;y=5*(x++)+10)
{ < >};
:
for (x=1, y=0; x<10;x++;y+=x);
a b (b-a)/k, (k=10), f(x), :
) n;
) e (e=0.0001).
.
n | ||||
, . x, ( n, e). an . .
:
X=...... SN=...... SE=..... Y=......
X=...... SN=...... SE=..... Y=......
..........
X=...... SN=...... SE=..... Y=......
X- ; SN- n; SE- ; Y- .
2
: .