.


:




:

































 

 

 

 


2




 

, /* */. , . , . , :

 

/* prog1.c */

main()

{

return 0;

}

 

, , , . ?

.c,.obj,.exe,.lib?

?

, 7.

 

 

4.

 

, . . , . notepad.exe, .bat. bcc32.exe, bcc.bat.

 

 

notepad.exe bcc.bat,

 

:

 

rem bcc.bat

if %1== goto error

path C:\Test\Bcc

bcc32.exe -IC:\Test\Include -LC:\Test\Lib %1.c

goto end

:error

echo ( .c)

:end

 

, MS DOS. , . bat batch , , . rem, , . , . %1; .

 

/* prog2.c */

main()

{

return 2;

}

 

 

bcc.bat prog2

 

%1 prog2. bcc.bat , %1 - , == - . if ,

 

if [ NOT ] 1 == 2

 

NOT : , .

 

1 == 2

 

, , , .

 

NOT , , .

 

if %1== goto error

 

: , , error. , , , , error , . echo, , , .

 

, error

 

path C:\Test\Bin

 

- Bin. , , . , Bin CBuilder, , .

 

bcc32.exe , . , %1. .; , - , %1.. goto end , error. end , .

 

, .

 

@echo off

 

( @ echo off):

 

rem bcc.bat

@echo off

if %1== goto error

path C:\Test\Bcc

bcc32.exe -IC:\Test\Include -LC:\Test\Lib %1.c

goto end

:error

echo ( .c)

:end

 

. bcc.bat , .

 

, , . errorlevel. :

 

"if [ NOT ] ERRORLEVEL .

 

 

ERRORLEVEL

 

, .

 

 

rem test.bat

@echo off

prog2.exe

if ERRORLEVEL %1 echo , %1

 

prog2.exe, prog2.c, 2 . , test.bat , . test/bat 0:

 

test. bat 0

 

@echo off prog2.exe.

. - if ERRORLEVEL %1 - - 0. 2 , 0, : echo : " , 2". , :

 

test.bat 1.

 

" , 1". test.bat 2. ERRORLEVEL %1 - : 2 , 2. echo : " , 2".

 

test.bat 3

 

: 2 , 3.

 

. C

 

rem test.bat

@echo off

prog2.exe

if NOT ERRORLEVEL %1 echo %1

 

:

 

test.bat 0

test.bat 1

test.bat 2

test.bat 3

 

 

5.

 

. Lib. , , , , . , Include. Include CBuilder:

 

C:\Test\Include

_defs.h

_nfile.h

_null.h

_stddef.h

stdio.h

 

h header . stdio.h (standard input/output /).

notepad.exe C:\Test\Apps prog3.c:

 

/*prog3.c*/

#include <stdio.h>

main

{

printf (I am a student);

return 0;

}

 

 

, . , . , , . # - , , , . , . include

 

#include <_>

 

include, .

printf (print , format , ) . .

 

bcc32.exe IC:\Test\Include -LC:\Test\Lib prog3.c

 

, Apps prog2.exe. , I am a student.

 

, printf , , \n:

 

printf (I am a student\n);

, :

printf (I am a student\n\n);

 

:

, #include <stdio.h> ;

? .

 

6.

 

, . , , . , , , . , , . - . , . :

 

/*prog4.c*/

 

#include <stdio.h>

 

main()

{

int x = 17, y = 18, z;

z = x*y;

printf(17 * 18 = %d\n, z);

return 0;

}

 

main x, y z. int (integer-) ; . x y 17, y 18. , x y z. x * y , , .

17 18 - . printf. . , , , , %, . - , , d , . , printf , . , printf. : 17 * 18 = 306.

 

. , .

 

int x=17, y=17*18;

 

, * 18 , , :

 

int x = 17, y;

y = x * 18;

 

, , scanf:

 

/*prog5.c*/

 

#include <stdio.h>

 

main()

{

int x, y, z;

z = x * y;

scanf (%d %d, &x, &y);

printf (%d * %d = %d\n, x, y, z);

return 0;

}

 

, , . 17 18 Enter (). 17 * 18 = 306. , , 44 55, 44 * 55 = 2420. x y, . scanf . printf scanf . & () , .. . ( , ), , . :

 

int x = 17, y = 18, z;

z = x * y;

printf (%d\n, x);

 

17, y 18. * . z 306, printf. scanf , , , , & scanf .

scanf , , scanf , .

 

/*prog6.c*/

 

#include <stdio.h>

 

main()

{

int x, y;

scanf ( = %d = %d, &x, &y);

printf (%d * %d = %d\n, x, y, x * y);

return 0;

}

 

:

 

=17 =18

 

, =, , = , 17 18. , , = , .

int , . . unsigned int . , #define:

 

#define UINT unsigned int

 

UINT define unsigned int. define .

 

:

+ ,

- ,

* ,

/ ( )

% .

 

, % printf, scanf , . . - , . () . , : , , .. .

 

%u, , . , , %d.

 

, , , , , , : , .

 

 

:

, , , ;

;

? ?

, , , . ? ?

? . ?

#define?

 

 

, , .

 

 

7.

 

float double. float . , , , a * bp, a , 0.5 < a <=1. b 2 ( ) 10 ( ), p , . double . , , . %f:

 

float x = 2.1, y = 3.8, z;

z = (x + y) / 2;

printf ( %f %f %f, x, y, z);

 

 

#unclude<math.h>

 

( math.h) main, :

 

double sin (double x) - ;

double cos (double x) - ;

double tan (double x) - ;

double asin (double x) - ;

double acos (double x) - ;

double atan (double x) - ;

double exp (double x) - ;

double log (double x) - ;

double log10 (double x) - ;

double sqrt (double x) - ;

double fabs (double x) - ;

 

 

(7.1) , , .

 

(7.2) , .

 

(7.3) , .

 

(7.4) , .

 

(7.5) , .

 

(7.6) , .

 

(7.7) , .

 

8.

 

. :

 

if ()

1

[ else

2 ]

 

. , 1, , else 2. , .

 

, , .

 

/*prog7.c*/

//

 

#include <stdio.h>

 

main()

{

float x, y;

scanf ( = %f, &x);

if (x >= 0)

y = x;

else

y = - x;

printf ( | %f | = %f\n, x, y);

return 0;

}

 

, , , :

 

if ()

{

1a

1b

...

}

[ else

{

2a

2b

...

}

]

 

:

> - ;

< - ;

>= - ;

<= - ;

== - ()

!= - .

 

==. = : (x = 1 x 1) (2 = 2 , 2 2). C = , , . , x = (y = 2) x y 2. ==, , . C 0, , , 1. , 2 == 2 (1), 2 == 1 (0).

 

:

&& - ();

|| - ();

! - ().

 

, . while:

 

while ()

.

 

, , . , .

 

/*prog8.c*/

// 1, 2,..., n

 

#include <stdio.h>

 

main()

{

unsigned int n, s = 0, i = 0; /* s , 1 n; n s */.

 

scanf (n = %u, &n);

 

while (i < n)

{

s = s + i * i;

i++;

}

 

printf ( 1 * 1 + 2 * 2 +...+ %u * %u = %u\n, n, n, s);

return 0;

}

 

for:

 

/*prog9.c*/

// 1, 2,..., n

 

#include <stdio.h>

 

main()

{

unsigned int n, s, i; /* s , 1 n; n s */.

 

scanf (n = %u, &n);

 

for (i = 1, s = 0; i <= n; i++)

s = s + i * i;

 

printf ( 1 * 1 + 2 * 2 +...+ %u * %u = %u\n, n, n, s);

return 0;

}

 

, , ; , for i 1, s - 0. i 1, s i. , i 1.

 

/*prog10.c*/

// , . , 0.

 

#include <stdio.h>

 

main()

{

unsigned int i, s = 0; /* s , , ; i , ; i s */.

 

scanf (%u, &i);

 

while (i!= 0)

{

s = s + i;

scanf (%u, &i);

}

 

printf ( %u\n, s);

return 0;

}

 

 

:

 

(8.1) , , ;

 

(8.2) , , ;

 

(8.3) , , ;

 

(8.4) , , ;

 

(8.5) , , ;

 

(8.6) , , ;

 

(8.7) , , ;

 

(8.8) n, 1, 2,..., n ( n! - n );

 

(8.9) , ; , ;

 

(8.10) , , ; , ;

 

(8.11) , , ; , ;

 

9.

 

char (character - ). ASCII-, , ( ). %.





:


: 2016-12-18; !; : 266 |


:

:

, , .
==> ...

2119 - | 1761 -


© 2015-2024 lektsii.org - -

: 0.32 .