Культин Н. Б. - c c++ в задачах и примерах - 2009
TRANSCRIPT
-
-
-
2009
-
681.3.068+800.92C/++ 32.973.26018.1 90
. . 90 /C++ : 2- ., . .
.: -, 2009. 368 .: . + CD-ROM
ISBN 978-5-94157-406-3 -
C/C++, -, , , , , , , . . - C/C++ . - , - . , -- .
681.3.068+800.92C/++ 32.973.26018.1
:
. .
02429 24.07.00. 28.07.09. 60901/16. . . . . 23.
2000 . "-", 190005, -, ., 29.
- 77.99.60.953..005770.05.09 26.05.2009 . .
" ""
199034, -, 9 , 12
ISBN 978-5-94157-406-3 . ., 2009 , "-", 2009
-
...................................................................................... 1 ....................................................................... 2 ........................................................................ 3
I. ................................................ 5 ................................................................... 7 ........................................................................... 7 .............................................................................................. 8
................................................................ 9 ........................................................................... 9 ............................................................................................ 10
................................................................................................ 14 ......................................................................... 14 ............................................................................................ 15 .................................................................................. 18 ............................................................................................ 18
................................................................................................... 20 ......................................................................... 20 ............................................................................................ 21
............................................... 22 ......................................................................... 22 ............................................................................................ 23
................................................................................................ 39 if ................................................................................ 39
.................................................................. 39 ..................................................................................... 40
-
IV
switch ........................................................................ 65 .................................................................. 65 ..................................................................................... 66
................................................................................................ 78 for ......................................................................................... 78
.................................................................. 78 ..................................................................................... 78 ......................................................................... 104
do ... while .......................................................................... 110 ................................................................ 110 ................................................................................... 110 ......................................................................... 121
while ................................................................................... 122 ................................................................ 122 ................................................................................... 122
.......................................................................................... 126 ....................................................................... 126 .......................................................................................... 126 ................................................................................ 152
.......................................................................... 160 ....................................................................... 160 .......................................................................................... 161 ................................................................................ 182
.......................................................................................... 188 ....................................................................... 188 .......................................................................................... 188 ................................................................................ 202
........................................................................................... 208 ....................................................................... 208 .......................................................................................... 209 ................................................................................ 248
.............................................................................................. 254 ....................................................................... 254 .......................................................................................... 255 ................................................................................ 269
.......................................................................................... 276 ................................................................................ 283
-
V
II. ........................................................ 295 ....................................................................297 ..................................................................298 .................................................................................298 .............................................................................298 .......................................................................................298 ..........................................................................................299
...........................................................................................299 .............................................................299 ...............................................................................................300 if ...............................................................................300 switch .......................................................................300
...............................................................................................301 for .............................................................................301 do while ....................................................................301 while .........................................................................302
......................................................................302 - ...................................................................303
printf ..............................................................................................303 scanf ..............................................................................................304 puts ................................................................................................305 gets ................................................................................................305 putch ..............................................................................................305 getch ..............................................................................................306 cputs ..............................................................................................306 cprintf ............................................................................................306 sprintf ............................................................................................307 textcolor .........................................................................................307 textbackground ..............................................................................308 gotoxy ............................................................................................309 clrscr..............................................................................................309 window ..........................................................................................309
...........................................................309 fopen ..............................................................................................309 fprintf .............................................................................................310 fscanf .............................................................................................311
-
VI
fgets ...............................................................................................311 fputs ...............................................................................................311 ferror .............................................................................................312 feof .................................................................................................312 fclose..............................................................................................312
........................................................312 strcat ..............................................................................................312 strcpy .............................................................................................313 strlen ..............................................................................................313 strcmp ............................................................................................313 strlwr .............................................................................................313 strupr .............................................................................................314 strset ..............................................................................................314 strchr .............................................................................................314
..............................................................314 abs, fabs .........................................................................................314 acos, asin, atan, acosl, asinl, atanl ...............................................315 cos, sin, tan cosl, sinl, tanl ............................................................315 exp, expl .........................................................................................315 pow, powl ......................................................................................316 sqrt .................................................................................................316 rand ...............................................................................................316 srand ..............................................................................................316
...............................................................317 atof .................................................................................................317 atoi, atol ........................................................................................317 gcvt ................................................................................................317 itoa, ltoa, ultoa ..............................................................................318
.....................................................318 arc ..................................................................................................318 bar .................................................................................................319 bar3d .............................................................................................319 circle ..............................................................................................320 drawpoly ........................................................................................321 ellipse ............................................................................................321 getmaxx, getmaxy ..........................................................................322 getx, gety........................................................................................322
-
VII
graphresult ....................................................................................322 grapherrormsg ..............................................................................322 initgraph ........................................................................................323 line .................................................................................................323 lineto ..............................................................................................323 linerel ............................................................................................324 moveto ...........................................................................................324 moverel ..........................................................................................324 outtext ............................................................................................325 outtextxy ........................................................................................325 pieslice ...........................................................................................325 putpixel ..........................................................................................326 rectangle ........................................................................................326 sector .............................................................................................327 setcolor ..........................................................................................328 setfillstyle.......................................................................................329 setlinestyle .....................................................................................329 settexstyle ......................................................................................330
..............................................................................331 delay ..............................................................................................331 sound .............................................................................................331 nosound .........................................................................................332
........................................................................... 333
1 ................................................................................ 335 ...................................................................... 335 ....................................................... 338 ................................ 339 , ............ 339
2. - ............................... 343 ...................................... 345 ............................................................... 347
-
, -
,
, .
? , , , . , ,
, .
, , -
, , , -
, .
.
-
.
:
.
C++. - , , -
, .
. ++, , -
. , -
Microsoft Visual C++ Borland C++ Builder.
-
2
, ? - -
, . ,
( - -
) ( , ,
-
,
), Borland C++ 3.1. ,
, . , -
,
. . . -
.
. -
, !
, -
-
. , -
.
,
-
. ( ), "" - .
,
, .
-
3
, ( ) - ,
. :
-, ;
; . , ,
.
.
-
I
-
, ,
:
. ,
. , -
C++ , -
,
.
: ;
. -
: = ;
( ).
++ , -, , Sum sum -
.
++ int (-) float ().
- .
-
I 8
1. , .
1 float a, b; //
float s; //
2. , .
2 float funt; //
float kg; //
3. , - .
3 float summa; //
int srok; // ()
int stavka; // ()
float dohod; //
4. , .
5. , .
5 float r1, r2; //
float s; //
6. , .
-
9
7. , - , ,
.
7 float CenaTetr; //
int KolTetr; //
float CenaKar; //
int KolKar; //
float CenaLin; //
float Summa; //
8. , - , -
.
, ,
:
, " ".
, C++ , ,
, -
x=x+dx x+=dx, i=i+1 -
: i++.
, -
.
. , n, -
int, 32767, -
-
I 10
n=n+1, n
-32768.
- ,
.
9. , x - 1,5.
10. , summa .
11. , - n.
11
n++;
12. , counter.
12
counter -= 2;
13. x1 x2.
14. - = 2,7x3 + 0,23x2 1,4.
14
y:=-2.7*x*x*x + 0.23*x*x - 1.4;
-
11
15. , - x , dx.
15 x += dx;
16. ( 405,9 ). 16 kg = funt*0.4059;
17. ( 1066,8 ).
18. - .
19. -
: has =21
, a ,
h .
20. -
: hbas +=2
, a b ,
h .
21. - : 2rs = .
21 // M_PI, "", math.h
s = M_PI * r * r;
-
I 12
22. - .
R
H
22 ( )= +
= s r h rv r h
22 // M_PI, "", math.h
s = 2*M_PI*r*(h+r);
v = M_PI *r*r*h;
23. - .
24. -
.
R
2
3
443
rs
rv
=
=
24 float r; //
float v, s; //
v = (3*M_PI*r*r*r)/4; // M_PI math.h
s = 4*M_PI*r*r;
-
13
25. - .
26. - .
)( 2221 rrhv =
1r
2r
h
27. - .
R
H
hrs = 231
28. :
).32(95
= F
29. - -
.
30. -
.
-
I 14
31. - , -
.
32. - , -
: 21
21rr
rrr
+
= .
33. .
34. - ,
, .
34 float ctetr, cobl, ckar; // ,
int ntetr, nkar; // -
float summ; //
// ,
//
summ = ntetr*(ctetr+cobl) + nkar*ckar;
, ,
:
printf - .
printf , -
-
15
,
.
-
, %.
:
y %i ; y %u ; y %f , ; y %n.mf ,
n ( , , -
); m .
, :
y \n ; y \t ; y \" ; y \\ \.
printf, puts.
, -
:
printf(" ");
getch();
35. , .
-
I 16
36. , , ( ). 36 #include
#include
void main()
{
printf("\n\n\n");
printf(" ");
getch(); //
}
37. , .
.
! !
,
.
. .
37 //
#include
#include
void main()
{
printf(" ! !\n");
printf(" -\n");
printf(" ,\n");
printf(" .\n\n");
printf(" . . \n");
printf("\n\n ");
getch(); //
}
-
17
38. a, b c ( float) -. : a = b = = c = .
38 printf("a=%5.3f b=%5.3f =%5.3f", a, b, c);
39. h w ( float), -. -
(=, =), - (). 39 printf(" = %3.2f \n = %3.2f \n", h, l);
40. , - m n (int). 40 printf("a=%i b=%i c=%i", a, b, c);
41. a, b c. -
.
41 printf("a=%i\nb=%i\nc=%i\n", a, b, c);
42. x1 x2. -
, -
, "".
-
I 18
, cprintf cputs. -
,
\r\n.
, cprintf cputs, - textcolor().
textbackground(). -
.
clrscr, textcolor textbackground, -
#include "conio.h".
43. , :
,
.
,
, .
. .
43 //
#include
void main()
{
textbackground(BLUE); //
textcolor(LIGHTGRAY); //
clrscr(); //
cprintf(" \n\r");
cprintf(" .\n\r");
-
19
cprintf(" ,\n\r");
cprintf(" , .\n\n\r");
cprintf(" . . \n\n\r");
cprintf("\n\n ");
getch();
}
44. , "- , ", -
( : , , -
, , , -
, ). .
44 //
#include
void main()
{
clrscr();
textcolor(RED);
cprintf(" \n\r");
textcolor(LIGHTRED); //
cprintf(" \n\r");
textcolor(YELLOW);
cprintf(" \n\r");
textcolor(GREEN);
cprintf(" \n\r");
textcolor(LIGHTBLUE);
cprintf(" \n\r");
textcolor(BLUE);
cprintf(" \n\r");
textcolor(MAGENTA);
-
I 20
cprintf("!\n\r");
textcolor(LIGHTGRAY);
cprintf("\n ");
getch();
}
, ,
:
scanf.
scanf , . -
,
. -
& (, ).
:
y %i ; y %u ; y %f ; y % ; y %s .
& , - scanf,
( , ).
-
21
45. , - kol .
46. , radius float.
47. , u r ( float). , -
( ). 47 scanf("%f", &u);
scanf("%f", &r);
48. , u r ( float). , .
48 scanf("%f %f", &u, &r);
49. ,
.
49 float r, h; //
float v; //
printf(" :\n");
printf(" -> ");
scanf("%f", &r);
printf(" -> ");
scanf("%f", &h);
-
I 22
50.
. , -
.
50 float sum; //
int period; // (- )
float rate; //
float profit; //
float value; //
printf(" (.) -> ");
scanf("%f, &sum);
printf(" (.) ->");
scanf("%i", &period);
, ,
:
, , -
.
- , .
-
23
:
51. . (, , ). : () -> 9 () -> 7.5 : 67.50 . .
51 //
#include
#include
void main()
-
I 24
{
float l,w; //
float s; //
printf("\n \n");
printf(" :\n");
printf(" (.) -> ");
scanf("%f", &l);
printf(" (.) -> ");
scanf("%f", &w);
s = l * w;
printf(" : %10.2f . \n", s);
printf("\n\n ");
getch();
}
52. .
53. . (, , ). : () -> 9 () -> 7.5 () -> 5 : 337.50 . .
54. -. -
(, , -). : () -> 9 () -> 7.5 () -> 5 : 90.00 . .
-
25
54 //
#include
#include
void main()
{
float l,w,h; // ,
float s; //
printf("\n \n");
printf(" :\n");
printf(" () -> ");
scanf("%f", &l);
printf(" () -> ");
scanf("%f", &w);
printf(" () -> ");
scanf("%f", &w);
s = (l*w + l*h + w*h)*2;
printf(" : %6.2f . \n",s);
printf("\n\n ");
getch();
}
55. . - (, , ). () -> 9.5 : 857.38 . .
56. . (, - , ). : () -> 5
-
I 26
() -> 10 1570.80 . .
56 //
#include
#include
void main()
{
float r,h,v; // ,
printf(" \n");
printf(" :\n");
printf(" () -> ");
scanf("%f", &r);
printf(" () -> ");
scanf("%f", &h);
v = 2*3.1415926*r*r*h;
printf("\n %6.2f . \n", v);
printf("\n ");
getch();
}
57. , - .
(, -, ). : (.) -> 2.75 -> 5 (.) -> 0.85 -> 2 : 15.45 .
-
27
57 //
#include
#include
void main()
{
float kar,tetr; //
int nk,nt; //
float summ; // }
printf("\n \n");
printf(" :\n");
printf(" (.) -> ");
scanf("%f", &tetr);
printf(" -> ");
scanf("%i", &nt);
printf(" (.) -> ");
scanf("%f", &kar);
printf(" -> ");
scanf("%i", &nk);
summ=tetr*nt + kar*nk;
printf("\n : %6.2f .\n", summ);
printf("\n ");
getch();
}
58. , -
.
(, , ). : (.) -> 2.75 (.) -> 0.5 (.) -> 7 : 22.75 .
-
I 28
59. - ( ), . - (, , ). : (.) -> 8.5 () -> 2.3 : 19.55 .
60. , . -
(, , ). : () -> 8.5 () -> 10 42.50 . .
61. ,
. -
(, , ). ( ) -> 25 17 -> 30 : 106.25 . .
61 //
//
#include
#include
#include "math.h" // sin M_PI - ""
void main()
{
-
29
float a,b; //
float u; // ,
float s; //
printf("\n \n");
printf(" ");
printf("() -> ");
scanf("%f%f", &a, &b);
printf(" ");
printf("(.) -> ");
scanf("%f", &u);
/* s=a*h/2, a - , h - .
h - h=b*sin(u).
sin .
1 . = 180/pi, pi - "").
*/
s = a*b*sin(u*M_PI/180)/2;
printf(" : %6.2f . ",s);
printf("\n\n ");
getch();
}
62. - , -
.
(, , ). . : () -> 15 () -> 20 : 8.57
62 // ,
// .
-
I 30
#include
#include
void main()
{
float r1,r2; //
float r; //
printf("\n \n");
printf(" \n");
printf(" :\n");
printf(" () -> ");
scanf("%f",&r1);
printf(" () -> ");
scanf("%f",&r2);
r=r1*r2/(r1+r2);
printf(" : %6.2f ",r);
printf("\n ");
getch();
}
63. - ,
. -
(, , - ). : () -> 15
()-> 27.3 ( ): 42.30
-
31
64. .
(, , ). : () -> 36 () -> 1500 : 0.024
65. - , . -
(, -, ). : ( ) -> 120 () -> 3.5 420 .
66. -. : (); ( ), 100 ; .
(, , ). () -> 67 ( 100 ) -> 8.5 (.) -> 19.20 109.34 .
66 //
#include
#include
void main()
{
float rast; //
-
I 32
float potr; // 100
float cena; //
float summ; //
printf("\n \n");
printf(" () -> ");
scanf("%f",&rast);
printf(" ( 100 .) -> ");
scanf("%f",&potr);
printf(" (.) -> ");
scanf("%f",&cena);
summ = 2 * potr/100 * rast * cena;
printf(" %6.2f .",summ);
printf("\n\n ");
getch();
}
67. , , . -
. , , -
.
() -> 1000 (.)-> 3.25 : 1000 : 3 25 = 205 : 17.56 /
67 //
#include
#include
void main()
{
float s; //
float t; //
-
33
float v; //
int min; //
int sek; //
float ts; //
printf(" \n");
printf(" () -> ");
scanf("%f", &s);
printf(" (.)-> ");
scanf("%f", &t);
min = t;
sek = (t - min) * 100;
ts = min * 60 + sek;
v = (s /1000) / (ts / 3600);
printf(": %4.0f \n", s);
printf(": %i %i = %4.0f \n", min, sek, ts);
printf(" %2.2f /\n", v);
printf("\n ");
getch();
}
68. . (, - , ). : () -> 5.5 () -> 7 665.23 .
69. . -
-
I 34
(, , -). : () -> 5.5 () -> 7 : 431.97 . .
69 //
#include
#include
#include "math.h" // M_PI - ""
void main()
{
float r; //
float h; //
float s; //
printf("\n \n");
printf(" :\n");
printf(" () ->");
scanf("%f", &r);
printf(" () ->");
scanf("%f", &h);
s = 2*M_PI*r*r +2*M_PI*r*h;
printf(" %6.2f . \n", s);
printf("\n ");
getch();
}
70. . (, , ). ,
-
35
( ). . -> 7.5 2.5 3 56.25 .
71. - (1 1600,94 ). (, , - ).
-> 100
100 - 160.09
71 //
#include
#include
void main()
{
float m; //
float k; //
printf("\n \n");
printf(" ->");
scanf("%f", &m);
k = m*1.60094;
printf("%6.2f - %6.2f \n", v,k);
printf("\n ");
getch();
}
72. (1 405,9 ). -
-
I 36
(, , ). -> 5 5 - 2.05
73. . , (% ) ( ) - . -
(, , ). : (.) -> 25000 () -> 6 () -> 10 ------------------------------------- : 1250.00 . : 262500.00 .
73 //
#include
#include
void main()
{
float summ; //
int srok; //
float stavka; //
float dohod; //
printf("\n \n");
printf(" :\n");
printf(" (.) -> ");
scanf("%f", &summ);
printf(" () -> ");
scanf("%i", &srok);
printf(" () -> ");
-
37
scanf("%f", &stavka);
dohod = summ * stavka/365/100 * srok; // 365 - -
summ = summ + dohod;
printf("----------------------------------\n");
printf(": %9.2f .\n", dohod);
printf(" : %9.2f .\n",summ);
printf("\n ");
getch();
}
74. -, , ,
. -
(, , ). ( )-> 150 150 - 2 . 30 .
74 // , ,
// ,
#include
#include
void main()
{
int min; //
int h; //
int m; //
printf(" ( ) -> ");
scanf("%i",&min);
h = (int)min / 60;
m = min % 60;
-
I 38
printf("%i . - %i .%i .\n", min, h, m);
printf("\n ");
getch();
}
75. , - . ,
12,5 12 . 50 . (, -, ). -> 23.6 23.6 . - 23 . 60 .
75 //
#include
#include
void main()
{
float f; //
int r; // ()
int k; // ()
printf("\n \n");
printf(" -> ");
scanf("%f",&f);
r = (int)f;
k = f * 100 - r*100;
printf("%6.2f . - %i . %i .\n", f, r, k);
printf("\n ");
getch();
}
-
39
76. (1 405,9 ). - (, , ). . -> 3.5 3.5 (/) - 1 420 .
77. , -, . -
(, -, ). ( ): x1,y1 -> -2 5 x2,y2 -> 1 7 x3,y3 -> 5 -3 : 23.56 . .
if , , :
if - .
, if, :
1
2
-
I 40
( ) - , if.
, else, -, , - , -
.
( ) , -
.
- if .
78. - , ,
. -
(, -, ). : () -> 15 ()-> 27.3 (1-, 2- ) -> 2 : 9.68
78 //
#include
#include
void main()
{
float r1,r2; //
float r; //
-
41
int t; // :
// 1 - ;
// 2 -
printf("\n \n");
printf(" :\n");
printf(" () ->");
scanf("%f", &r1);
printf(" () ->");
scanf("%f", &r2);
printf(" ");
printf("(1-, 2-) ->");
scanf("%i", &t);
if (t == 1)
r = r1 + r2;
else r = r1*r2 / (r1+r2);
printf(" : %6.2f \n", r);
printf("\n ");
getch();
}
79. . : . -. 5000 ., 10%, , 13%. (, , ). , . -> 10000 , . -> 12 ---------------------------- : 10000.00 . : 12 . : 13 : 1300.00 . : 11300.00 .
79 //
#include "stdio.h"
-
I 42
#include "conio.h"
void main()
{
float sum; //
int period; //
float percent; // ,
float profit; //
float total; //
printf("\n\n");
printf(", . -> ");
scanf("%f",&sum);
printf(" , . -> ");
scanf("%i",&period);
if ( sum < 5000)
percent = 10;
else
percent = 13;
profit = sum * percent/100/12 * period;
total = sum + profit;
printf("\n: %3.2f .", sum);
printf("\n : %i .", period);
printf("\n : %2.2f", percent);
printf("\n: %3.2f .", profit);
printf("\n : %3.2f .", total);
printf("\n\n ");
getch();
}
-
43
80. . : . -. 5000 ., 9%, 5000 ., 10 000 ., 11%, 10 000, 13%. (-, , ). , . -> 15000 , . -> 6 --------------------------- : 15000.00 . : 6 . : 13.00 : 975.00 . : 15975.00 .
80 //
#include "stdio.h"
#include "conio.h"
void main()
{
float sum; //
int period; //
float percent; //
float profit; //
float total; //
printf("\n\n");
printf(", . -> ");
scanf("%f",&sum);
printf(", . -> ");
-
I 44
scanf("%i",&period);
if ( sum < 5000)
percent = 9;
else
if ( sum < 10000)
percent = 11;
else
percent = 13;
profit = sum * percent/100/12 * period;
total = sum + profit;
printf("\n---------------------------");
printf("\n: %3.2f .", sum);
printf("\n: %i", period);
printf("\n: %3.2f", percent);
printf("\n: %3.2f .", profit);
printf("\n : %3.2f .", total);
printf("\n\n ");
getch();
}
81. -. 912 1015. - 10, 5%. (, , ). (1 912; 2 1015) > 2 , . -> 15 ---------------------------- : 3.20 . : 15 . : 48.00 . : 2.40 . : 45.60 .
-
45
81 // -
//
#include "stdio.h"
#include "conio.h"
void main()
{
int format; // : 1 - 912; 2 - 1015
int kol; //
float cena; //
float sum; //
float discount = 0; //
float total; //
printf("\n\n");
printf(" (1 - 9x12; 2 - 10x15) -> ");
scanf("%i",&format);
printf(", . -> ");
scanf("%i",&kol);
if ( format == 1 )
cena = 2.50;
else
cena = 3.20;
sum = cena * kol;
if ( kol > 10 )
-
I 46
{
discount = sum * 0.05;
total = sum - discount;
}
printf("\n-------------------------");
printf("\n: %3.2f .", cena);
printf("\n: %i", kol);
printf("\n: %3.2f .", sum);
if ( discount != 0)
{
printf("\n: %3.2f .", discount);
printf("\n : %3.2f .", total);
}
printf("\n\n ");
getch();
}
82. , , - (I = P/U, : I , ; P , ; U , ). - ,
( ), -. (-, , ). , -> 60 , -> 0 ! .
82 //
#include
-
47
#include
void main()
{
float P,U,I; // , ,
printf("\n \n");
printf(", -> ");
scanf("%f", &P);
printf(", -> ");
scanf("%f", &U);
if (U != 0)
{
I = P / U;
printf(" : %5.2f , I);
}
else
printf("! !\n");
printf("\n ");
getch();
}
83. . . -
(, , ). : () -> 3.5 () -> 7 !
83 //
#include
-
I 48
#include
void main()
{
float r1,r2; //
float s; //
printf("\n :\n");
printf(" () -> ");
scanf("%f",&r1);
printf(" () -> ");
scanf("%f",&r2);
if (r1 > r2)
{
s = 2 * 3.14 * (r1 - r2);
printf("\n %6.2f .\n", s);
}
else
{
printf("\n! ");
printf(" .\n");
}
printf("\n ");
getch();
}
84. , - . -
, ,
. -
. ,
, .
(.) -> 2.90 ! 60
84 //
#include
-
49
#include
void main()
{
float t; // , 1.25
int ts; //
int min; //
int sek; //
printf(" (.) -> ");
scanf("%f", &t);
min = t; // t float, - ""
sek = (t - min) * 100;
if (sek > 60)
{
printf("!");
printf(" 60");
}
else
{
ts = min * 60 + sek;
printf("%i %i = %i ", min, sek, ts);
}
printf("\n ");
getch();
}
85. , , -. -
. , , .
, 2000, ->2001 2000
85 // ,
#include
#include
-
I 50
void main()
{
int year;
int r; // year 4
printf(" , 2001, ");
printf("->");
scanf("%i", &year);
r = year % 4;
if ( r )
printf("%i - \n", year);
else
printf("%i - \n", year);
printf("\n ");
getch();
}
86. . -
, -
, . -
(, , ). -> 12 27 -10 : x1= -25.551 x2= -28.449
86 //
#include
#include
#include "math.h"
void main()
{
-
51
float a,b,c; //
float x1,x2; //
float d; //
printf("\n \n");
printf(" ");
printf(" ");
printf("-> ");
scanf("%f%f%f", &a, &b, &c); //
d = b*b - 4*a*c; //
if (d < 0)
printf(" \n");
else {
x1 = (-b + sqrt(d))/(2*a);
x2 = (-b - sqrt(d))/(2*a);
printf(" : x1=%3.2f x2=%3.2f\n", x1, x2);
}
printf("\n ");
getch();
}
87. . 10% , 1000 . (, , -). -> 1200 10% : 1080.00 .
88. . 3% , 500 , 5% 1000 . -
-
I 52
(, , ). -> 640 3% : 620.80 .
88 //
#include
#include
void main()
{
float summ; //
printf("\n \n");
printf(" ");
printf("-> ");
scanf("%f", &summ);
if (summ < 500)
printf(" .\n");
else {
printf(" ");
if (summ > 1000) {
printf("5%\n");
summ = 0.97 * summ;
}
else {
printf("3%\n");
summ = 0.97 * summ;
};
printf(" : %3.2f .\n", summ);
}
printf("\n ");
getch();
}
-
53
89. -. , -
.
(, -, ). -? -> 1705 , - 1703
89 //
#include
#include
void main()
{
int year; //
printf("\n -?\n");
printf(" ");
printf("-> ");
scanf("%i", &year);
if (year == 1703)
printf(".");
else {
printf(" , ");
printf("- 1703 .\n");
}
printf("\n ");
getch();
}
90. . ,
.
-
I 54
(, -, ). ? -> 1939
91. . . -
.
(, , ). : 1. 2. 3. -> 3 . -
91 //
#include
#include
void main()
{
int otv; //
printf(" :\n");
printf("1. \n");
printf("2. \n");
printf("3. \n");
printf(" ");
printf("-> ");
scanf("%i", &otv);
-
55
if (otv == 2)
printf(".");
else {
printf(" .\n ");
printf(" \n");
}
printf("\n ");
getch();
}
92. . . -
.
(, , ). : 1. , - 2. - 3. -> 1 . : 2
93. , . ,
, , , -
. .
-> 34 67
34 67
93 //
#include
#include
void main()
-
I 56
{
int a,b; //
printf("\n ");
printf(" ");
printf("->");
scanf("%i%i", &a, &b);
if (a == b)
printf(" ");
else if (a < b)
printf("%i %i\n", a, b);
else printf("%i %i\n", a, b);
printf("\n ");
getch();
}
94. , , , -
"!" " -" .
(, , - ). 67 ? -> 56 . 67=42
94 //
#include
#include
#include // srand
#include // time
void main()
{
int m1, m2, p; //
-
57
int otv; //
time_t t; // -
//
srand((unsigned) time(&t));; //
//
m1 = rand() % 9 +1; // rand() 9
// 0 8
m2 = rand() % 9 +1;
p = m1 * m2;
printf(" %ix%i ?\n", m1, m2);
printf(" ");
printf("-> ");
scanf("%i", &otv);
if (p == otv)
printf(".");
else
printf(" .\n%ix%i=%i", m1, m2, p);
printf("\n ");
getch();
}
95. , ( 100), , "!" " " - .
(, , -). 83-17 ? -> 67 . 83-17=66
96. , , - . -
-
I 58
(, -, ). -> 23 23 - .
96 //
#include
#include
void main()
{
int n; //
printf("\n ");
printf("-> ");
scanf("%i", &n);
printf(" %i ");
if (n % 2 == 0)
printf(".");
else
printf(".");
printf("\n\n ");
getch();
}
97. , , . -
(, -, ). -> 451 451
98. - 20%- ,
-
59
.
(, , -). : ( ) -> 3 (1 - , ... 7 - ) -> 6 20%. : 5.52 .
98 //
// ,
#include
#include
void main()
{
int time; //
int day; //
float summa; //
printf("\n \n");
printf(" :\n");
printf(" ");
printf("( - ) ->");
scanf("%i", &time);
printf(" ");
printf(" (1-,..,7-) ->");
scanf("%i", &day);
summa = 2.3 * time; // 2.3 .
if (day == 6 || day == 7)
{
printf(" 20%\n");
summa = summa * 0.8;
};
-
I 60
printf(" : %3.2f .\n",summa);
printf("\n ");
getch();
}
99. , ,
.
: () 100. (, -, ). () () ->170 68 2.00 .
99 //
#include
#include
void main()
{
float w; //
float h; //
float opt; //
float d; //
printf("\ , ,\n");
printf(" () (), ");
printf("->");
scanf("%f%f", &h, &w);
opt = h - 100;
if (w == opt)
printf(" !");
else
-
61
if (w < opt)
{
d = opt - w;
printf(" %2.2f .\n", d);
}
else
{
d = w - opt;
printf(" %2.2f .\n", d);
}
printf("\n ");
getch();
}
100. , -
. , -
" ".
.
( 1 12) -> 11
100 //
#include
#include
void main()
{
int month; //
puts("\n ( 1 12)");
printf("-> ");
scanf("%i", &month);
if (month < 1 && month > 12)
-
I 62
printf(" 1 12");
else if (month >= 3 && month = 6 && month = 9 && month
-
63
if (n > 100)
r = n % 100;
else r = n;
// r -
if ( r >= 11 && r = 2 && r 31 12 2008 ! ! 1.1.2009
104 //
#include
#include
-
I 64
void main()
{
int day;
int month;
int year;
int last; // 1,
int r; // ,
// year 4
printf(" () ");
printf(" \n");
printf("( ) -> ");
scanf("%i%i%i", &day, &month, &year);
last = 0;
if (month == 2) {
if ((year % 4) != 0 && day == 28) last = 1;
if ((year % 4) == 0 && day == 29) last = 1;
}
else if ((month == 4 || month == 6 ||
month == 9 || month == 11)
&& (day == 31))
last = 1;
else if (day == 31)
last = 1;
if (last == 1) {
printf(" !\n");
day = 1;
if (month == 12) {
month = 1;
year++;
printf(" !\n");
}
else month++;
-
65
}
else day++;
printf(" %i %i %i",day,month,year);
printf("\n ");
getch();
}
switch , , :
switch - .
, switch, :
1 2 3 d
n1
n3
n2 default
- ,
case.
- , case, -
, default.
- - .
-
I 66
105. , -. : ( , ) (, , ). (, , ). () > 75 () > 150 : 1 2 3 > 3 ----------------------------- . : 350.00 . : 1.13 . . : 393.75 .
105 // -
//
#include "stdio.h"
#include "conio.h"
void main()
{
float w,h; // ,
int m; // :
// 1 - ; 2 - ; 3 - ;
float cena; // 1 . .
float s; //
float sum; //
printf("\n\n");
printf("\n (.) -> ");
-
67
scanf("%f",&w);
printf(" () -> ");
scanf("%f",&h);
printf(":\n");
printf("1 - \n");
printf("2 - \n");
printf("3 - \n");
printf(" ->");
scanf("%i",&m);
switch ( m )
{
case 1: cena = 200; break;
case 2: cena = 250; break;
case 3: cena = 350; break;
default: cena = 0; break;
}
if ( cena != 0 )
{
s = (w * h) / 10000;
sum = s * cena;
printf("\n . : %3.2f .", cena);
printf("\n: %3.2f . ", s);
printf("\n : %3.2f .", sum);
}
else
printf("\n ");
printf("\n\n ");
getch();
}
-
I 68
106. , - . :
(912, 1015 1824) . - 10, 10%. (, , ). : 1 912 2 1015 3 1824 > 1 > 12 ----------------------------- : 3.50 . : 12 . : 42.00 . : 4.20 . : 37.80 .
106 // -
#include "stdio.h"
#include "conio.h"
void main()
{
int k; //
int f; // : 1 - 912; 2 - 1215; 3 - 1824
float cena; // 1 .
float sum; //
float discount; //
float itog;
printf("\n\n");
printf(":\n");
printf("1 - 912\n");
-
69
printf("2 - 1215\n");
printf("3 - 1824\n");
printf(" ->");
scanf("%i",&f);
switch ( f )
{
case 1: cena = 3.50; break;
case 2: cena = 5.00; break;
case 3: cena = 8.50; break;
default: cena = 0; break;
}
printf(" (.) -> ");
scanf("%i",&k);
if ( cena != 0 )
{
sum = k * cena;
printf("\n .: %3.2f .", cena);
printf("\n: %i .", k);
if ( k > 10 )
{
discount = sum * 0.1;
itog = sum - discount;
printf("\n: %3.2f .",sum);
printf("\n: %3.2f .", discount);
printf("\n : %3.2f .",itog);
}
else
-
I 70
printf("\n : %3.2f .", sum);
}
else
printf("\n ");
printf("\n\n ");
getch();
}
107. , - . : (- 92, 95, 98 ) . (, - , ). : 1 92 2 95 3 98 4 DT > 2 > 25 ----------------------------- : 20.30 . : 25 : 507.50 .
107 // -
#include "stdio.h"
#include "conio.h"
void main()
{
int m; // : 1 - 92; 2 - 95; 3 - 98; 4 - DT
float cena; // 1
float litr; //
float sum; //
-
71
printf("\n\n");
printf(" :\n");
printf("1 - 92\n");
printf("2 - 95\n");
printf("3 - 98\n");
printf("3 - DT\n");
printf(" ->");
scanf("%i",&m);
switch ( m )
{
case 1: cena = 17.50; break;
case 2: cena = 20.30; break;
case 3: cena = 25.40; break;
case 4: cena = 18.50; break;
default: cena = 0; break;
}
printf(" -> ");
scanf("%f",&litr);
if ( cena != 0 )
{
sum = litr * cena;
printf("\n : %3.2f .", cena);
printf("\n: %3.2f", litr);
printf("\n : %3.2f .", sum);
}
else
printf("\n ");
printf("\n\n ");
getch();
}
-
I 72
108. , .
,
.
108 //
#include
#include
void main()
{
int nd; //
puts("\n (1..7");
printf("->");
scanf("%i", &nd);
switch (nd)
{
case 1: puts(""); break;
case 2: puts(""); break;
case 3: puts(""); break;
case 4: puts(""); break;
case 5: puts(""); break;
case 6: puts(""); break;
case 7: puts(""); break; default: puts(" 1..7");
}
getch();
}
109. , . :
3 . 6 . 12 . 18 . 24 . 36 . 9,0% 11,5% 13,5% 15,0% 18,0% 24,0%
-
73
109 //
#include "stdio.h"
#include "conio.h"
void main()
{
float value;
int period;
float rate;
float profit;
printf("value->");
scanf("%f",&value);
printf("period->");
scanf("%i",&period);
switch ( period )
{
case 3: rate=9.0; break;
case 6: rate=11.5; break;
case 12: rate=13.5; break;
case 18: rate=15.0; break;
case 24: rate=18.0; break;
case 36: rate=24; break;
default: period = 0;
}
if ( period !=0 )
{
printf("\nrate: %6.2f", rate );
profit = value * rate/100/12 * period;
-
I 74
printf("\nprofit: %6.2f", profit);
}
else
printf("Not valid period");
printf("");
getch();
}
110. , - ( , ). : . ,
(, , ). (.) 423 2,2
495 1,0
815 1,2
846 1,4 : -> 423 ()-> 3 : : 2.20 . : 6.60 .
110 //
//
#include
#include
void main()
-
75
{
int kod; //
float cena; //
int dlit; //
float summ; //
printf("\n .\n");
printf(" :\n");
printf(" ( - ) ->");
scanf("%i", &dlit);
puts(" ");
puts("\t432");
puts("\t\t495");
puts("\t815");
puts("\t\t846");
printf("->");
scanf("%i", &kod);
printf(": ");
switch (kod)
{
case 432: puts("");
cena = 2.2;
break;
case 495: puts("");
cena = 1;
break;
case 815: puts("");
cena = 1.2;
break;
case 846: puts("");
cena = 1.4;
break;
default: printf(" .");
cena = 0;
-
I 76
}
if (cena != 0) {
summ = cena * dlit;
printf(" : %i .\n", cena);
printf(" : %3.2f .\n", summ);
}
printf("\n ");
getch();
}
111. , - . -
: ( ( ) ) modd m Y Y c c+ + +
+
+
15 13 1 4 4 2 777 7
.
d , m , , ( 1, 2, ..., 12), Y , c -. ,
.
: 1 , 2 , ..., 6 , 0 . 111 //
#include
#include
void main()
{
int day,month,year; // , ,
int c,y; //
int m; //
int d; //
puts("\n ");
-
77
puts(" : .");
puts(", 5 12 2001");
printf("->");
scanf("%i %i %i", &day, &month, &year);
if (month == 1 || month == 2)
year--; //
//
m = month - 2; //
if (m
-
I 78
for , , :
for - .
, for, :
K-
- - .
- .
112. , 10 .
113. , y = 2,4x2 + 5x 3 2 2, 0,5. .
--------------- x | y --------------- -2 | -22.60 -1.5 | -15.90 -1 | -10.40
-
79
-0.5 | -6.10 0 | -3.00 0.5 | -1.10 1 | -0.40 1.5 | -0.90 2 | -2.60 ----------------
113 //
#include
#include
#define LB -2.0 //
#define HB 2.0 //
#define DX 0.5 //
void main()
{
float x,y; //
int n; // -
int i; //
n = (HB - LB)/DX +1;
x = LB;
printf("------------------\n");
printf(" x | y\n");
printf("------------------\n");
for (i = 1; i
-
I 80
114. , . -
.
-------------- -------------- 1 1 2 4 3 9 4 16 5 25 6 36 7 49 8 64 9 81 10 100 --------------
114 //
#include
#include
void main()
{
int x = 1; //
int y; //
int i; //
printf(" \n");
printf("-----------------\n");
printf("\t\n");
printf("-----------------\n");
for (i = 1; i
-
81
printf("-----------------\n");
printf("\n ");
getch();
}
115. , . -
.
. -------------- -------------- 1 1 3 9 5 25 7 49 9 81 --------------
116. , ( 0,5 ) (v = gt, g = 9,8 /2 ). .
------------------------- , , / ------------------------- 0.0 0.00 0.5 4.90 1.0 9.80 1.5 14.70 2.0 19.60 2.5 24.50 3.0 29.40 -------------------------
117. , - . : , . ,
() . . -
.
C (.) -> 150000 (.) -> 12 () -> 14
-
I 82
----------------------------------- ----------------------------------- 1 150000.00 1750.00 14250.00 2 137500.00 1604.17 14104.17 3 125000.00 1458.33 13958.33 4 112500.00 1312.50 13812.50 5 100000.00 1166.67 13666.67 6 87500.00 1020.83 13520.83 7 75000.00 875.00 13375.00 8 62500.00 729.17 13229.17 9 50000.00 583.33 13083.33 10 37500.00 437.50 12937.50 11 25000.00 291.67 12791.67 12 12500.00 145.83 12645.83 ----------------------------------- : 11375.00
117 //
#include "stdio.h"
#include "conio.h"
void main()
{
float value; //
int period; //
float rate; //
float debt; // ,
float interest; // ( )
float paying; //
float suminterest; //
printf(", .,-> ");
scanf("%f",&value);
printf(", .,-> ");
scanf("%i",&period);
printf(" , -> ");
-
83
scanf("%f",&rate);
debt = value;
suminterest = 0;
printf("-----------------------\n");
printf(" \n");
printf("-----------------------\n");
for ( int i = 1; i 0 t2 > 10 dt> 1 ----------------- C F ----------------- 0.00 32.00 1.00 33.80 2.00 35.60 3.00 37.40
-
I 84
4.00 39.20 5.00 41.00 6.00 42.80 7.00 44.60 8.00 46.40 9.00 48.20 10.00 50.00 -----------------
118 //
//
#include "stdio.h"
#include "conio.h"
void main()
{
float t1,t2,dt; //
float c,f; //
int n; //
printf("t1->");
scanf("%f",&t1);
printf("t2->");
scanf("%f",&t2);
printf("dt->");
scanf("%f",&dt);
n = (t2 - t1)/dt + 1;
c = t1;
printf("\n----------------\n");
printf("\n C F\n");
printf("\n----------------\n");
for (int i=0; i
-
85
f = (float)9/5 * c + 32;
printf("%5.2f %5.2f\n", c,f);
c = c + dt;
}
printf("\n----------------\n");
printf("\n \n");
getch();
}
119. , - (1 = 2,54 ). -
.
120. , n .
.
(, , ). -> 20 20 210
120 // n
#include
#include
void main()
{
int n; // -
int summ; //
int i; //
printf(" \n");
printf(" -> ");
-
I 86
scanf("%i", &n);
summ = 0;
for (i = 1; i 12 12 156
122. , n : 1, 3, 5, 7 ... . -
(, -, ). : 1,3,5,7, ...
->15 15 330
122 // : 1,3,6,9 ...
#include
#include
void main()
{
int e; //
-
87
int n; // -
int summ = 0; //
int i; //
printf(" : 1,3,6,9, ...\n");
printf(" -> ");
scanf("%i", &n);
e = 1;
for (i = 1; i 15
15 3.3182
123 // 1+1/2+1/3+ ...
#include
#include
void main()
{
-
I 88
int n; // -
float i; // ; int,
// 1/i
//
float elem; //
float summ = 0 ; //
printf(" 1+1/2+1/3+...\n");
printf(" - \n");
printf("-> ");
scanf("%i",&n);
summ = 0;
for (i = 1; i
-
89
124 //
#include
#include
void main()
{
int n; //
int x; // 2 n
printf("\n \n");
x = 1;
for (n = 0; n 7 7 5040
126. , . -
. , -
, .
. -> 5.4 -> 7.8
-
I 90
-> 3.0 -> 1.5 -> 2.3 : 4.00
127. , - -
. -
. .
. -> 5 . -> 5.4 -> 7.8 -> 3.0 -> 1.5 -> 2.3 : 4.00
128. , -
-
. .
-> 12.3 : 1 : 12.30 . .: 12.30 -> 15 : 2 : 27.30 . .: 13.65 -> 10 : 3 : 37.30 . .: 12.43 -> 5.6 : 4 : 42.90 . .: 10.73 -> 11.5 : 5 : 54.40 . .: 10.88
128 // , -
#include
-
91
#include
#define L 5 //
void main()
{
float a; //
int n; // -
float sum; //
float sred; //
printf("\n \n");
printf(" ");
sum = 0;
for (n = 1; n
-
I 92
. , ,
.
. -> 5 . -> 5.4 -> 7.8 -> 3.0 -> 1.5 -> 2.3 : 5 : 4.00 : 1.5 : 7.8
129 //
//
// ,
#include
#include
void main()
{
float a; //
int n; //
float sum; //
float sred; //
float min; //
float max; //
int i; //
printf(" .\n");
printf(" ->");
scanf("%i", &n);
printf(" .\n");
printf(" ");
printf("->");
-
93
scanf("%f",&a); //
// , :
min = a; //
max = a; //
sum = a;
//
for (i = 1; i < n; i++)
{
printf("->");
scanf("%f", &a);
sum += a;
if (a < min) min = a;
if (a > max) max = a;
}
sred = sum / n;
printf(" : %i\n", n);
printf(" : %6.2f\n", sred);
printf(" : %6.2f\n", min);
printf(" : %6.2f\n", max);
printf("\n ");
getch();
}
130. , - 10 ( 1 10), . -
.
1 3 4 2 7 4 9 6 2 1 . .: 3.90
-
I 94
131. , - ( 1 10).
.
.
6 10 4 2 5 8 1 7 7 3 . .: 5.30 10 3 6 1 10 1 3 8 7 6 . .: 5.50 5 2 2 5 4 2 2 1 6 10 . .: 3.90
131 //
//
#include
#include
#include // srand rand
#include
#define L 10 //
#define N 3 //
void main()
{
int r; //
int sum; // summa
float sred; //
int i,j; //
time_t t; // -
//
srand((unsigned) time(&t));; // //
for (i = 1; i
-
95
sum = 0; // !
for (j = 1; j 16.50 , . , . 100 1.65 200 3.30 300 4.95 400 6.60 500 8.25 600 9.90 700 11.55 800 13.20 900 14.85 1000 16.50
133. , y = | x |. 4 4, 0,5.
-
I 96
133 // y=|x|
#include
#include
#include "math.h"
#define LB -4 // -
#define HB 4 // -
#define DX 0.5 //
void main()
{
float x,y; //
int n; // -
int i; //
printf("\n y=|x| \n");
n = (HB - LB)/DX + 1;
x = LB;
for (i = 1; i
-
97
135. , -, , 7. .
72=14 73=21 74=28 75=35 76=42 77=49 78=56 79=63
135 // 7
#include
#include
void main()
{
int m; // ,
// ()
int n; //
int p; //
m = 7;
printf("\n %i\n", m);
for (n = 1; n
-
I 98
136. , - . -
.
1 2 3 4 5 6 7 8 9 10 1 1 2 3 4 5 6 7 8 9 10 2 2 4 6 8 10 12 14 16 18 20 3 3 6 9 12 15 18 21 24 27 30 4 4 8 12 16 20 24 28 32 36 40 5 5 10 15 20 25 30 35 40 45 50 6 6 12 18 24 30 36 42 48 54 60 7 7 14 21 28 35 42 49 56 63 70 8 8 16 24 32 40 48 56 64 72 80 9 9 18 27 36 45 54 63 72 81 90
136 // -
#include
#include
void main()
{
int i,j; //
printf(" "); //
for (j = 1; j
-
99
137. , : 1 1/3 + 1/5 1/7 + 1/9 /4 ( , /4). 137 // ""
// 1 -1/3 + 1/5 - 1/7 + ...
#include
#include
void main()
{
float x; //
int n; //
float summ; //
int i; //
// (~1000)
// , ""/4
printf(" 1 -1/3 + 1/5 - 1/7 + ...\n");
printf(" - ->" );
scanf("%i", &n);
summ = 0;
for (i = 1; i
-
I 100
138. f(x) = 5x2 x + 2 . x1, x2 x .
x1 x2x
138 //
// ( for)
#include
#include
void main()
{
float a,b; //
float dx; //
float s; //
int n; //
float x; //
float y; //
int i;
printf("\ \n");
printf(" -> ");
scanf("%f", &a);
printf(" -> ");
scanf("%f", &b);
printf(" -> ");
-
101
scanf("%f", &dx);
n = (b - a) / dx + 1;
x = a;
s = 0;
for (i = 1; i
-
I 102
float a,b; //
float dx; //
float s; //
int n; //
float x; //
float y1,y2; //
int i;
printf("\n \n");
printf(" \n");
printf(" -> ");
scanf("%f", &a);
printf(" -> ");
scanf("%f", &b);
printf(" -> ");
scanf("%f", &dx);
n = (b - a) / dx;
x = a;
s = 0;
for (i = 1; i
-
103
. -
.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
141. , - . -
.
0 255
->49
49 00110001
141 //
#include
#include
void main()
{
int dec; //
int v; //
int i; //
printf("\n \n");
printf(" 0 255 ");
printf("-> ");
scanf("%i", &dec);
printf(" %i ", dec);
v = 128; // ()
for (i = 1; i
-
I 104
{
if (dec >= v)
{
printf("1");
dec -= v;
}
else printf("0");
v = v / 2; //
}
printf("\n\n ");
getch();
}
142. . 10 : 10 "", 9 8 "", 7 6 "", 6 "-". . -
.
*** *** . 5x3=15 77=49 14=4 43=12 94=36 88=64 78=52 ! 78=56 47=28 35=15 25=10 : 9 : .
142 //
#include
-
105
#include
#include // srand rand
#include
void main()
{
int numb1,numb2; //
int res; //
int otv; //
int kol = 0; //
int i; //
time_t t; // -
//
printf("\*** ***\n");
printf(" ");
srand((unsigned) time(&t));; // //
for (i = 1; i
-
I 106
{
case 10: puts("5"); break;
case 9: puts("4"); break;
case 8: puts("4"); break;
case 7: puts("3"); break;
default: puts("2"); break;
}
printf("\n ");
getch();
}
143. 100. 10 ,
, . .
.
: 10 "", 9 8 "", 7 6 "", 6 - "". -
. .
. 75-4=71 35-9=29 ! 35-9=26 14-1=13 6-5=1 37-19=28 ! 37-19=18 53-14=39 94-87=7 90-16=74 4-2=2 89-41=48 : 8 :
143 //
#include
#include
-
107
#include // srand rand
#include
#define LEVEL 97+2 // 2 99
void main()
{
int numb1,numb2; //
int op; // :
// 0 - , 1 -
char zop; // - "" ""
int res; //
int otv; //
int kol = 0; //
int buf; // numb1 numb2,
// numb1
-
I 108
{
res = numb1 + numb2;
zop = '+';
}
else
{ //
zop = '-';
if (numb1 < numb2)
{
// numb1 numb2
buf = numb2;
numb2 = numb1;
numb1 = buf;
}
res = numb1 - numb2;
}
printf("%i%c%i=", numb1, zop, numb2); //
scanf("%i", &otv); //
if (otv == res)
kol++;
else printf(" . %i%c%i=%i\n",
numb1, zop, numb2, res);
}
printf(" : %i\n", kol);
printf(" :\n");
switch (kol)
{
case 10: puts("5"); break;
case 9: puts("4"); break;
case 8: puts("4"); break;
case 7: puts("3"); break;
default: puts("2"); break;
}
-
109
printf("\n ");
getch();
}
144. , "- ", , ,
, .
144 //
#include
#include
#include "dos.h" // delay
void main()
{
int min,sec; // ,
clrscr(); //
_setcursortype(_NOCURSOR); //
printf(" , ");
for (min = 0; min
-
I 110
do ... while , ,
:
do while , . . ( do while) .
, do while, :
while - .
do while .
do while , -
.
do while, , ,
, .
145. , - y = 2,4x2 + 5x 3.
-
111
.
.
x1 -> -2 x2 -> 2 dx -> 0.5 --------------- x | y --------------- -2 | -22.60 -1.5 | -15.90 -1 | -10.40 -0.5 | -6.10 0 | -3.00 0.5 | -1.10 1 | -0.40 1.5 | -0.90 2 | -2.60 ----------------
145 //
#include
#include
void main()
{
float x,y; //
float x1,x2,dx; //
printf("x1 -> ");
scanf("%f",&x1);
printf("x2 -> ");
scanf("%f",&x2);
printf("dx -> ");
scanf("%f",&dx);
x = x1;
-
I 112
printf("------------------\n");
printf(" x | y\n");
printf("------------------\n");
do
{
y = -2.4*x*x+5*x-3;
printf("%6.2f | %6.2f\n" ,x ,y);
x += dx;
}
while ( x 0 t2 > 10 dt> 1 ----------------- C F ----------------- 0.00 32.00 1.00 33.80 2.00 35.60 3.00 37.40 4.00 39.20 5.00 41.00 6.00 42.80 7.00 44.60 8.00 46.40 9.00 48.20 10.00 50.00 -----------------
-
113
146 //
//
#include "stdio.h"
#include "conio.h"
void main()
{
float t1,t2,dt;
float c,f;
printf("\n ");
printf("\n \n");
printf("t1->");
scanf("%f",&t1);
printf("t2->");
scanf("%f",&t2);
printf("dt->");
scanf("%f",&dt);
printf("\n---------------------\n");
printf("\n C F\n");
printf("\n---------------------\n");
c = t1;
do
{
f = (float)9/5 * c + 32;
printf("%5.2f %5.2f\n", c,f);
c = c + dt;
}
while ( c
-
I 114
printf("\n---------------------\n");
printf("\n ");
getch();
}
147. , - ,
. -
(, , -). - . . . >45 >23 >15 >0 : 3 : 83 : 27.67
147 //
//
#include
#include
void main()
{
int a; // ,
int n; //
int s; //
float m; //
s = 0;
n = 0;
printf("\ ");
printf(" .\n");
-
115
printf(" . .\n");
do {
printf("-> ");
scanf("%i", &a);
if (a > 0)
{
s += a;
n++;
}
} while (a > 0);
printf(" : %i\n", n);
printf(" : %i\n", s);
m = (float) s / n;
printf(" : %3.2f", m);
printf("\n\n ");
getch();
}
148. , -
( ). (, - , ). - . . . >56 >75 >43 >0 : 75
148 //
//
#include
#include
void main()
-
I 116
{
int a; //
int m; //
puts("\n ");
puts(" .");
puts(" . .");
m = 0;
do {
printf("-> ");
scanf("%i", &a);
if (a > m) m = a;
} while (a > 0);
printf(" : %i", m);
printf("\n ");
getch();
}
149. , - -
( ). - (, , ). - . . . >12 >75 >10 >9 >23 >0 : 9
149 //
//
#include
-
117
#include void main()
{ int a; //
int min; // printf("\n \n");
printf(" .\n");
printf(" . .\n");
printf("-> ");
scanf("%i", &a);
min = a; //
while ( a > 0)
{
if (a < min) min = a;
printf("-> ");
scanf("%i", &a);
}
printf(" : %i\n", min); printf("\n ");
getch();
}
150. , , - ( , ). - . , -
, .
-> 17 17 - .
150 // ,
#include
#include
-
I 118
void main()
{
int n; //
int d; //
int r; // n d
printf(" -> ");
scanf("%i", &n);
d = 2; //
do {
r = n % d;
if (r != 0) d++;
}
while ( r != 0 ); // n d
if (d == n)
printf("%i - " ,n);
else printf("%i - " ,n);
printf("\n\n ");
getch();
}
151. .
,
. -
.
151 //
#include
#include
#include
void main()
{
-
119
float x1,x2; //
float e; //
float dx; //
int n; //
float x; //
float y; //
float st; //
float sp; //
int i;
printf("\ \n");
printf(" -> ");
scanf("%f", &x1);
printf(" -> ");
scanf("%f", &x2);
printf(" -> ");
scanf("%f", &e);
dx = 0.5;
st = 0;
do
{
sp = st;
dx = dx / 2;
n = (x2 - x1) / dx;
x = x1;
st = 0;
for (i = 0; i
-
I 120
st = st + (y * dx);
x += dx;
}
printf(" : %6.3f\n", st);
}
while ( abs(sp - st) > e);
printf("\n ");
getch();
}
152. , "" - 1 10 .
(, , ). " ". "" 1 10. . -> 5 . -> 3 ! !
152 // " "
#include
#include // srand
#include
void main()
{
int comp; //
int igrok; //
int n; //
time_t t; // -
//
srand((unsigned) time(&t));
-
121
comp = rand() % 10 +1 ; // 1 10
clrscr();
cprintf("\n\r \"\" 1 10.\n\r");
cprintf(" ");
n = 0;
do {
cprintf("\n\r->");
cscanf("%i",&igrok);
n++;
} while ((igrok != comp)&&(n < 3));
if (igrok == comp)
{
textcolor(RED+BLINK);
cprintf("\n\r !");
}
else
{
textcolor(GREEN);
cprintf("\n\r .);
cprintf(" %d",comp);
}
textcolor(LIGHTGRAY);
cprintf("\n\r ...");
getch();getch();
}
153. . -
. -
, .
-
I 122
while , ,
:
While , . . ,
.
, do while, :
while , - ( ).
while , , , -
.
while - , ,
.
154. , - y = 2x2 5x 8 4 4. - 0,5.
-
123
154 //
#include
#include
void main()
{
float x,dx; //
float x1,x2; //
float y; //
x1 = -4;
x2 = 4;
dx = 0.5;
x = x1;
printf("--------------\n");
printf(" x | y\n");
printf("--------------\n");
while (x < x2)
{
y = x*x + 2;
printf("%3.2f | %3.2f\n", x, y);
x += dx;
}
printf("--------------\n");
printf("\n ");
getch();
}
155. , "" . ,
1 1/3 + 1/5 1/7 + 1/9 ..., - , /4.
-
I 124
(, -, ). -> 0.001 0.001000 3.143589 502 .
155 // ""
#include
#include
void main()
{
float p; //
float t; //
int n; //
float el; //
p = 0;
n = 1;
el = 1; //
printf("\n -> ");
scanf("%f", &t);
printf(" %f\n",t);
while (el >= t )
{
el = (float) 1 / (2*n -1);
if ((n % 2) == 0)
p -= el;
else p += el;
n++;
}
p = p*4;
printf("\n %f %f\n", t, p);
printf(" %i .\n", n); printf("\n ");
getch();
}
-
125
156. , .
156 //
// ( )
#include
#include
void main()
{
int n1,n2; // ,
int nod; //
int r; // n1 n2
printf("\n ");
printf(" .\n");
printf(" ");
printf(" ");
printf("-> ");
scanf("%i%i", &n1, &n2);
printf(" %i %i - ", n1, n2);
while (n1 % n2)
{
r = n1 % n2; //
n1 = n2;
n2 = r;
}
nod = n2;
printf("%i\n", nod);
printf("\n ");
getch();
}
-
I 126
, ,
:
, -, , .
.
.
() . - , .
0 n 1, n .
.
- , #define.
, (for, while).
- , . . -
.
157. , - ,
. -
.
-
127
-
.
a[0] -> 10 a[1] -> 16 a[2] -> 14 a[3] -> 5 a[4] -> 10 a[5] -> 22 a[6] -> 22 : 10 16 14 5 10 22 22 : 14.00
157 // ,
#include
#include
void main()
{
int a[7]; //
int sum; //
float m; //
int j;
printf("\n ");
printf(" \n");
//
for ( j = 0; j < 7; j++)
{
printf("na[%i] -> ", j);
scanf("%i",&a[j]);
}
//
printf("\n: \n");
-
I 128
for ( j = 0; j < 7; j++)
{
printf("%i ", a[j]);
}
sum = 0;
//
for ( j = 0; j < 7; j++)
{
sum = sum + a[j];
}
m = sum / 7;
printf(" : %f", m);
printf("\n ");
getch();
}
158. , , -
, .
-
.
a[1] -> 12 a[2] -> 0 a[3] -> 3 a[4] -> -1 a[5] -> 0 ------------------------- : 3
158 //
// ( )
#include
-
129
#include
#define SIZE 5 //
void main()
{
int a[SIZE]; //
int n = 0; // - -
int i; //
printf("\n .\n");
printf(" ");
printf(" \n");
for (i = 0; i < SIZE; i++)
{
printf("a[%i] ->",i+1);
scanf("%i", &a[i]);
if (a[i] != 0) n++;
}
printf(" %i .\n", n);
printf("\n ");
getch();
}
159. , - . -
(, , ). 5 -> 23 0 45 -5 12 : -5
159 //
#include
#include
-
I 130
#define HB 5 //
void main()
{
int a[HB]; //
int min; //
int i; //
printf("\n \n");
printf(" ");
printf("%i \n", HB);
printf("-> ");
for (i = 0; i < HB; i++)
scanf("%i",&a[i]);
min = 0; // , -
// -