.


:




:

































 

 

 

 





 

C()

 

, , .

, , .. .

, , .

, .

, ( ) ( ). , , .

, Borland C, Visual C++, Builder C++ -.cpp.

.obj. (), , . . () . Ÿ (Linker). .exe , , .

, , , , . :

1) ;

2) .

. . .

.

.

( 95), 0 9. , (, , , .

: (.), (,), , ,:,;, +, -, _, *, /, \, |, <, >, =,!,?, #, %, (,), [, ], {, }, ~, ^, &.

. : ++, --, ==,!=, <=, >=, >>, <<, ||, &&, +=, -=, *=, /=, /*, */, //,?:.

/*, */ - , , .

// - . .

. , .

, , , . , , . . .

() , . .

: , . : (int, while, cos).

. . , .

 

: () ().

: , . (short), (long), (unsigned). (signed c ) .

 

:

char   -128127
int   -32768..32767
short 2(1) -32768..32767
long   -2147483648.. 2147483647
unsigned int   0..65535
unsigned long   0..424967295
float   -3.14*10^-38..3.14*10^38
. double   -1.7*10^-308..1.7*10^308

 

char . .

har c=65;/* 65 */

printf (%c, c); /* */

printf (%d, c); /* 65 */

printf , % . % , %d .

, , .

 

()

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

:

int a = 5, b; /* , */

float x, y = 7.15 /* */

const.

.

:

const float PI=3.1415;

. .

 

, , , , . :

< >

< typedef>

< >

< >

<>

:

< ><>< >(<>)

{ //

< > }
< >

} //

 

.

. () . . :

1) #.

2)

3) , .

:

#define

#include

#define () , :

#define PI 3.1415927

PI .

#include . < > . , .

#include <stdio.h> /*stdio.h , /*/

#include <conio.h> /*, ( ).

clrscr(): -

getch(); - , */

#include <math.h> /* . */

 

:

#define PI 3.1415927

#include <stdio.h>

#include <conio.h>

void main (); //

{ int num = 13; // num

clrscr ();

printf (\n pi=%7.5f\n %d \n, PI, num);

getch();

}

 

void , main .

printf \n . pi=, - - , . %7.5f : f , PI, 7.5 , 7 , 5 . %d num.


 

-//-

, L(l). , 25L ( L int ), L long.

: 0 7-, 0. , 020(8)=16(10).

0 9- A F, 0x (0X). , 0x1F(16)=31(10)

L long. double. : n.m n.m Ep n.m ep. , 25.41 0.2541E+2.

, . , . , \n , \t , \0 , .

, . , . . 0.

. . enum, . , enum {A,B,C,D}; , . A=0, B=1, C=2, D=3. . , enum {A=10, B, C, D}; A=10, B=11, C=12, D=13.

: enum {A=20, B=30, C=35, D,=40}. , . , Color enum {Red, Green, Blue}; Color C1,C2; C1 C2 .

 

. . , , . . , . -5, : 2+3, : ?:.

, , a+b+c à (a+b)+c. , .

. +, -, *, /, % - , ++ - , -- - . +,-,*,/ . , . % . ++ . , (- ). , x=x+1; x++; ++x; .

. , int a=3, b=2, y; y=a++*b++; a=4, b=3, y=6. : =4, b=3< y=12. .. ++ -- , , . 1)y=a*b, 2)a++, 3)b++. 1)++a, 2)++b, 3)y=a*b.

. - <>=<>; , . .. . , i=j=k=0; ßà k=0, j=k, i=j. x=2+(y=1)-(z=0); ßà y=1; z=0; x=2+1-0. +=, -=, *=, /=, %=. , x+=2; ßà x=x+2; x-=a+b; ßà x=x-(a+b); d%=2; ßà d=d%2.

 

, , . .

char, short à int à unsigned à long à double

float à double

, .. . :

- char short int

- double, double

, . int i,j; float x; x=i; i=x; . float, float int . double float .

:

()

int a, b; float y;

a=5; b=2;

y=5/2; //y=2, ..

y=(float)a/b; //y=2.5 .. float.

 


 

 

 

a+b>0 && b+c>0

a>b || a>c

, a+b>0 , .

, a>b (a>c) .

 

. .

:

1) ~ - , .

2) & - , .

3) | - .

4) ^ - .

5) >> - .

6) << - .

, . 4- . ~ . , 1 0 .

() , . .. x<<2 x 2 , , 4. k- 2k. 2k.

x<<2 ßà x*22

x>>2 ßà

.

<1>,,< N> N. , , .

M=(i=1, j=i++, k=6, n=i+j+k); ßà i=1, j=i++ (j=1), k=6. n=2+1+6=9àm=9

j=i, i++

 

sizeof()

:

1) sizeof ()

2) sizeof ()

, , , . . , , .

: sizeof(int) 2 4, ( ).

sizeof(1.5) 8.

 

?:

(3), ( if).

:

(< 1>)?<2>:< 3>;

:

- 1, , 2, , 3.

max=(a>b)?a:b;

(a>b)?puts( , ):puts().

 

, () [ ].

 

1) putchar ()

2) puts (s)

3) printf () .

: printf (<. >, < >);

. .

:

%<>< >.<>

<> :

1) - - (

2) + - .

< > - , , .

<> - - .

.

:

%d %i .

%c

%s

%e

%f

%u

%

%x 16

%p

%ld

%lf , .. double

% (%%).

printf(

:

\n

\t

\v

\b

\r -

\a

\?

C (, ), . - .

 

1) getch () .

2) gets (s); - Enter

3) scanf () .

:

scanf(< >,< >);

, .. , . . &, & .

 

math.h. , abs double.

abs(x) - |x| - , x-.

acos(x) arccos (x)

asin(x) arcsin (x)

atan(x) arctg (x)

cos(x) cos x

cosh (x) ch x

ceil(x) - >=x

exp(x) - ex

fabs(x) - |x|, x

floor(x) <=x

fmod (x/y) x y

log(x) ln x

log10(x) lg x

pow(x,n) xn

sin(x) sin x

sinh(x) sh x

sqrt(x) x

tan(x) tg x

tanh(x) th x


 

3 :

-

-

-

. , ;. :

1)

2)

3) , .

:. , .

: , (), .

. , , {}, ; .

:

if c 2 . 2 :

-

-

:

if () ;

, . , . . if.

if (x>) x=0;

if (i!=1) j+1, s=1; // i , .

 

if (i!=1)

{ j+1; s=1;} //

if (getch ()!=27) k=0; // , escape.

if (i>0 && i<n) k++; //

if (a++) b++; // a++

 

:

if () 1;

else 2;

, 1, 2. 1 2 . ; else .

1) if (x>0) j=k+10;

else m=i*10;

2) if (x>0 && k!=0) {j=x/k; x+10;}

else m=k*i+10;

1 2 , , if-else, else if, else.

if (n>0)

if (a>b) z=a;

else z:=b;

else if (a>b). else if, .

if (n>0) {

if (a>b) z=a; }

else z:=b;

1- if.

!

- = ==.

 

()

switch () .

:

switch () {

case 1: 1

case 2: 2

case N: N

default: N+1

}

, . , . . , . ( break) . , . . . default , switch. break () switch.

switch break

int i=2;

switch (i) {

case 1: puts( 1); break;

case 2: puts( 2); break;

case 3: puts( 3); break;

default: puts( default); break; }

 

2. break , :

- default.

4 . : 1, , 2.

 

#include <stdio.h>

void main ()

{

double a,b,c; char s;

m1: fflush (stdin); // stdin

printf(\n 1, , 2:);

scanf(%lf%c%lf,&a,&s,&b);

switch(s) {

case +: c = a+b; break;

case -: c = a-b; break;

case *: c = a*b; break;

case /: c = a/b; break;

default: printf (\n , !); goto m1;

}
printf(\n a %c b = %lf, s, c);

printf(\n ? (Y/y));

s = getch();

if((s==Y)||(s==y)) goto m1;

printf(\n Good bye!);

}

 

, , . Enter:

1 2: 2.4+3.6

:

a + b = 6.000000

? (Y/y)

y (Y), :

1, , 2:

2r3, :

, !

1, , 2: 2*3

a*b = 6.000000

Continue? (Y/y)

, y Y

Good bye!


, .. , , , .

. ( ), ( ).

. :

-

-

-

 





:


: 2017-02-11; !; : 706 |


:

:

: , .
==> ...

1960 - | 1579 -


© 2015-2024 lektsii.org - -

: 0.159 .