WWW.DISSERS.RU


...
    !

Pages:     | 1 |   ...   | 6 | 7 || 9 | 10 |   ...   | 21 |

B o cyae oepaop 1 oec oo oa, oa paee ee aee True. B poo cyae oepaop poycaec 1 oec cey oepaop.

Bo-opx, ec eoxoo o oee ooo oepaopa, cyae, oa paee pae aee, True False, o ceye cooa cocao oepaop.

if B = 0.0 then Writeln ('eee a y eooo.').

else begin Ratio: = A / B;

Writeln ('Ooee =', Ratio) end;

B ao npuepe coyec o oepaop peoe if cocao else.

O E P A T O P B O P A C A S E B A C A E Oepaop case acae ooe cpeco opa aepa. ooe ye oeco oepaopo if.

Oepaop case coco pae (ceeopa) cco oepaopo, aoy oopx peecye ea oo e a, o ceeop. o a, o a oe oec o oepaop, y oopoo aee coaae c ey aee ceeopa. Ec coae ae e pocxo, o e oec o oepaopo, xox case e oc oepaop, coe oce eoaeoo coa else.

Mema case coco oo oeca oca aaoo, paeex a, a oop ceye oeoe.

Hanpuep:

x x y = x x case x of 1..5: y:= x;

6..10: y:= cos(x);

end; {case} aao acaec e yx oca, paeex y oa ... T oca oe cooecoa y ceeopa. Oepaop, co oce oeo, oec o cyae, ec aee ceeopa coaae co aee oca , ec eo aee oaae aao ae.

O e p a o p o p a s w i t c h C switch (paee) { case ocaoe paee 1: oepaop 1; break;

case ocaoe paee 2: oepaop 2; break;

.

.

case ocaoe paee n: oepaop n; break;

default: oepaop;

} ocpy switch aee paee oopa oepaop if else. -a eeoc ocpy if else e C p popapoa oo yco oe yc pac a peooee pyoce a, a e a paee o popa. ooy oopaoe cooae oepaopa if else po ae a oepaop switch.

oce oe pae aooe oepaopa eo peya oceoaeo cpaaec c oca pae, aa c caoo epxa o ex op, oa e ye ycaoeo x cooece. a oo cooece ycaoeo aa oc oepaop yp cooecye e case. Ec cpe oepaopo ocycye oepaop break, o ypaee epexo a ceyee ocaoe paee poepa pooaec. oo o oo ea, oepaop ao e aaa oepaopo break. oce oe oceoaeoc oepaopo oo e case, oopa aepaec oepaopo break, pocxo xo oepaopa switch. Oo switch pe oa, oa xo, o a oea oa oceoaeoce oepaopo ecox oox.

aa oceoaeoc oepaopo oe coepa o oee oepaopo. ype co o cyae e cac.

puep:

Switch (n) { case 1: printf ("n = %d", n); break;

case 2: printf ("n = %d", n+n); break;

case 3: printf ("n = %d", nn); break;

default printf ("n e pae [1;3]");

}.

Bea default oe ocycoa. Ec oa ec, o oceoaeoc oepaopo, cox oce default oec oa, oa cpaee co ce oca pae oo.

O e p a o p g o t o coyec epea ypae yp popa o ooo oepaopa pyoy. B ax C aca cyecy oe oepaop ee o, ooe ea cooa aoo oepaopa, apyeo paoy oopa o oa popa. peee oo oepaopa caec ox ce popapoa, a ca oepaop aa "oop popaca".

Cacc: goto eaop;

paee eycoo epeaec a oepaop popa, oeeo e e eaopo (eo).

p eo cooa ceye:

e xo yp oa e;

e xo yp oepaopo if, if/else, switch;

e xo yp epaoo cpyyp oepaopo a.

c o a o e p a C a oepa coyec oo C eco ocpy if/else, ec xoe ee oepaop c poc pae.

peya = (paee) paee 1: paee 2;

puep ucnooau:

int i = 2, j = 6, result;

result = (i

printf ("%d", result);

epeeo result ye pcoeo aee i ec paee co, j o.

, epaoe cpyyp (a. 14) oo o oopee oex oepaopo.

co oope eoopx ax cpoao, a pyx opeeec poecce cea oo ecox poepo yco.

T o e o c p y c e x a o p o c a 1 Peypcue aopum. ece aop, oopx aee eoopo y a ao ae ce ac o ae o y, oyeo a peye ae, aaec peypc aopo. B ocoe peypcoo aopa e peyppea opya. Haoee poco ee : x=x+1.

2 mepauo u. Eo ocoeoc o, o co oope oepa ee a apaee eeco. Ha ao ae ce pocxo oceoaeoe pee poepa yco oce cooo peyaa.

Bxo a ocyecec cyae oe aoo yco.

3 Boee u. Boo cya, oa yp ooo a eoxoo oop eoopy oceoaeoc oepaopo, .e. opaoa ype . Taa cpyypa oya aae a e oeoo a. ya oe o oe pao. p cooa ao cpyyp oo aoo pee eoxoo oc ypeeo a o e ce oepaop, apaep oopx e ac o ypeeo a.

1 4 O E P A T O P O B B C A C A E ACA C While ycooe paee do While (coe ycooe paee) oepaop; oepaop;

for c ao 1 (pee) for ec:= paee1 to - for (paee aa;

paee2 do oepaop; ycooe paee;

for c ao 1 (epe) paee epa) for ec:= paee1 downto oepaop;

paee2 do oepaop; do repeat oepaop;

oepaop while ( coe ycooe paee);

until ooe ycooe paee Cmu npopaupoau. Oepaop ea a pacoaac o aooo cac a e o ooceo eo.

c p e y c o e w h i l e poepa yco e while pooc epe oee ea a. Ec peya ycooo pae TRUE e pae y ( C), .e. paee co, o oec o oepaopo ea a. epe xoo while ep pa oo apy oy ecoo epeex, o ycooe paee eo aee.

Oepaop ea a o e ae oo ecox epeex ycooo pae c e, o ycooe paee opaoc 0 ( C) po aee FALSE ( acae) pepaoc oee ea a. while aepaec ceyx cyax: ec opaoc o ycooe paee aooa a; ec ee a cooa oepaop break; ec cooa oepaop return opa y. B epx yx cyax ypaee epeaec a oepaop, pacooe eocpeceo a o, pee cyae pocxo opa y. o pepa oee popa ecoeoo a ao aa Ctrl+C. Ec o e ooae, o opooa Ctrl+Alt+Del.

puep:

#include // oea oa oa #include // oea pao c oa main () // aa y (ocoo o popa) { int Count; // ocae epeex Count = 1; // aa opeee oox ace ycooo pae while (Count <= 10) { printf "pacy poa!");

Count++; // eee ae epeeo opaa ceyeo aa a } printf ("o oe");

getch ();

} aca oa aa C coco o, o eco oepaopa cpae a paeco = = coyec =.

ooc aaoo paoae while acae, anpuep:

program Hello; { popa} var Count: Integer; {ocae epeeo} Begin {aao ocooo oa popa} Count := 1; {pcoee aaoo ae epeeo} while (Count <= 10) do begin Writeln ('pacy poa!');

Inc (Count); {eee aa epeeo opaa a} end;

Writeln ('o oe');

end. {oe ocooo oa popa} Bo-epx, caaa epeeo Count pcoc aee paoe 1. ae, p xoe poepec ycoe:

aee Count ee pao 10. Ec a, o oec eo a (oepaop, axoec ey e coa begin....end acae { } C.) Ha pa oc cooee "pacy poa". aee Count yeaec a 1. Boec opa a aao a. aee Count poepec aoo eo a oec o, o ex op oa aee epeeo Count yoeope yco. a oo aee Count caoc pa 11, aepaec, a pa oc cooee "o oe".

F O R B A C A E Bapa oo a acae a ee, a opae. Oo, aop oepaopo oec cpoaoe co pa, oa epeea (eca) pae aee yaao aaoe. Mopye aoy popay Hello cey opao.

program Hello var Count: Integer;

begin for Count: = 1 to 10 do Writeln ('pacy poa!');

Writeln ('o oe');

end.

p oe o popa o, o for oec a e, a while.

Cacc a for:

for ec:= paee1 to paee2 do oepaop;

ec ec capa epeea (eoo a, cooo, yecoo oo epecoo a);

paee 1 paee 2 pae a, coecoo c o eca; oepaop oo cocao oepaop. ec yeaec a 1 oce aoo oe a. ec oo yea a 1. oo eoe coo to aeec a downto.

a eocao a for o oooc ye ye ec oo a 1.

Ocoe peyeca paoc, oooc cooa cooo epecoo a aaoe ae.

f o r C Haoee oe opo o C ec for. for C aoo oee, e acae pyx ax. ocpy eo cey opao:

for ([paee aa];[ycooe paee];[paee epa]) oepaop;

Bpaee aa coyec ycao aax ae epeex, ypax o.

cooe paee o paee, p coc oopoo oepaop ea a yy oc.

Bpaee epa opeee eee ae epeex, ypax o.

Cxea oe a for:

1 Boec paee aa;

2 Bcec ycooe paee;

3 Ec aee ycooo pae ca, o oc oepaop ea a;

4 Boec paee epa;

5 Boec ycooe paee ..;

6 a oo ycooe paee pao y, ypaee epeaec oepaopy, ceyey a o.

o oocc a c peycoe. poepa yco cea oec aae a. Ec ycoe oo, o eo a oe pay e oc.

puep ucnooau onepamopa for for (i = 0;i<10; i ++) printf ("apa ca %d%d", i, ii); // cec apa ce o 0 o 9.

for oo cec y while (a. 15).

15 wi t e For (paee 1;paee 2;paee 3) paee 1;

oepaop; while (paee 2) {oepaop;

paee 3;} oycaec cooa aooe a ecoo pae aa ecoo pae epa.

o ae oooc oc oc a.

puep 1: popaa, oopa acae cpoy C opao ope:

main ();

{ int top, lot; char string[100], temp;

for (top=0, lot=100;top

strring[top]=string[lot];

string[lot]=temp;

}} puep 2: ec ce ee ca o 100 o 0 ope ya.

1. for (i=100;i>=0;i-=2) printf ("%d", i);

2. for (i=100;i>=0;i--) if (i%2==1)continue;

else printf ("%d", i);

3. for (i=100;i>=0;printf ("%d", i), i-=2);

Bce p a ea oo oe, o aca pex pax apaax.

For oo cooa a ecoe , anpuep:

for (;;) {oepaop;} xoa aoo a oo coyec oepaop break.

puep a for, oop oe oecea aepy:

for (i=0;i<1000;i++);

Bpyx ax popapoa o e e cea po a, .e. apaep a for acae oe oo e, a C eece.

c o c y c o e Ocoeoc: oepaop ea a oc xo o pa eaco o yco.

d o w h i l e C Cacc:

do {oepaop;} while (ycooe paee);

do while pepaae oc, oa ycooe paee pao y caoc o.

Cxea oe a do while:

1 Boec oepaop;

2 Boec paee. Ec paee e pao y, o oee pooaec c epoo ya. Ec paee pao y, o oec oepaop, cey a o.

#include // oea oa-oa main () // aa y (ocoo o popa) { int A, B; // ocae epeex (eoe) float Ratio; // ocae epeex (eeceoe) char Ans; // ocae epeex (co) do { printf ("Bee a ca"); // o cooe a pa scanf ("%i", &A); // o A scanf ("%i", &B); // o B Ratio = A / B; // oepaop printf ("\nOoee pao %lg", Ratio); // o ae epeeo printf ("\noop (Y/N)"); // o opoca scanf ("%c", &Ans); // o oea } while ( Ans! = 'N'); // oe a } R E P E A T U N T I L B A C A E repeat until paccop a pepe popa, e oopee oepaopo ac o oea a opoc.

program DoRatio;

var A, B: Integer;

Ratio: Real;

Ans: Char;

begin repeat Write ('BBee a ca');

Pages:     | 1 |   ...   | 6 | 7 || 9 | 10 |   ...   | 21 |



2011 www.dissers.ru -

, .
, , , , 1-2 .