of 52 /52
Κων/νου Στυλιάδη Έτοιµες Ασκήσεις σε Pascal Φλώρινα, Οκτώβριος 2000
• Author

ria-karagianni
• Category

## Documents

• view

68

3

TAGS:

Embed Size (px)

### Transcript of Pascal Exercises

/

Pascal

, 2000

/

Pascal

Program prostesi; { } (* *) Uses Crt; { Crt, } Var { } a, b, c : Real; { } Begin { , . } Read(a, b); { } c := a+b; { } Write(c) { } End. { } (* ; := *)

Program misthos; (* *) Uses Crt; Var HM, ME, MA, KP, KA : Real; { , , , } Begin Read(HM, ME); MA := ME*HM; KP := 0.20*MA; KA := MA-KP; Write(MA, KP, KA) End.

2

/

Pascal

Program fahr_cel; (* *) (* : CEL = ((FAHR-32)*5)/9 *) Uses Crt; Const factor = 32.0; { } Var bath_fahr, bath_cel : Real; { bath_fahr bath_cel } Begin Writeln(' '); Writeln(' '); Writeln; { } Write(' : )'; Readln(bath_fahr); { } { } bath_cel := ((bath_fahr-factor)*5.0)/9.0; Writeln(' ', bath_cel, ' '); Writeln; { } End.

3

/

Pascal

. Program Strings; Uses Crt; Const stathera = ' Enter : '; Var prompt_1 : String; prompt_2 : String; input_str : String; Begin Clrscr; { } prompt_1 := stathera; prompt_2 := ' : '; Write(prompt_1); Readln(input_str); Write(prompt_2); Writeln(input_str); End. : Enter : Turbo Pascal 6.0! : Turbo Pascal 6.0! 255 . . Program Circle_Area; Uses Crt; Const Pi = 3.1415926; Var aktina, area : Real; Begin Clrscr; Writeln(' : '); Readln(aktina); area := (Pi * (aktina*aktina)); Writeln(' = ', area:8:2); Writeln; End. { area:8:2 8 area 2 }

4

/

Pascal

Program Concatenation; Uses Crt; Var Str1, Str2, Str3 : String[20]; { 20 } Begin Clrscr; Str1 := ''; Str2 := ''; Str3 := Str1+Str2; { } Writeln('Str1 + Str2 = ', Str3); End.

Program Ypoloipo; { } Uses Crt; Var x, y : Longint; Begin Clrscr; Writeln(' : '); Readln(x); y := x mod 3; { x/3 } { , y } Case y of 0 : Writeln(''); {y=0} 1 : Writeln(''); {y=1} 2 : Writeln('') {y=2} end; { case } { , , , } Repeat until keypressed; End.

5

/

Pascal

Program Athroisma; { , 1.000 } Uses Crt; Var a, s : Real; Begin Clrscr; s := 0; { } Repeat { } Readln(a); { s 1000 } s := s+a Until s>1000; Writeln(s); Repeat until keypressed; End.

6

/

Pascal

Program Foros; { , . } Uses Crt; Const ekptosh = 500,000; { } ekptosh_boys = 100,000; { } Var boys, eisodima, forologiteo, foros : Longint; { Longint 32767 Integer } Begin Clrscr; Writeln(' : '); Readln(eisodima); Writeln(' : '); Readln(boys); { } forologiteo := eisodima - ekptosh - boys*ekptosh_boys; foros := forologiteo div 3; { 1/3 } { Writeln , , . , } Writeln(' : ', eisodima, ' : ', forologiteo, ' : ', foros); Repeat until keypressed; End.

7

/

Pascal

Program CharacterCount; { # } Uses Crt; Var LetterCount, DigitCount : Integer; Character : Char; Begin Clrscr; { , } LetterCount := 0; { } DigitCount := 0; { } { # #, While } While Character '#' do Begin Readln(Character); { } { } If ('A' max then max := c; Writeln(' : ', max); Repeat until keypressed; End.

9

/

Pascal

Program Monos_Zygos; { } Uses Crt; Var k, p, y : Longint; Begin Clrscr; Writeln(' : '); Readln(k); p := k div 2; { } y := k mod 2; { } If y = 0 then Writeln(' ') Else Writeln(' '); Repeat until keypressed; End. Program Misthodosia; { , 20% , 20% 5% } Uses Crt; Var hmerom, meres_erg, yperories, mikta, krathseis, foros, kathara : Real; Begin Clrscr; Writlen(' : '); Readln(hmerom); Writeln(' : '); Readln (meres_erg); Writeln(' : '); Readln(yperories); { } mikta := hmerom * meres_erg + yperories * hmerom * 0.2; krathseis := 0.2 * mikta; { } foros := 0.05 * (mikta - krathseis); { } kathara := mikta - krathseis - foros; { } Writeln(' : ', mikta, ' : ', kathara, ' : ',krathseis); Repeat until keypressed; End.

10

/

Pascal

Program Antistrofh; { } Uses Crt; Var x, p, y, x1 : Byte; Begin Clrscr; Writeln(' : '); Readln(x); p := x div 10; { } y := x mod 10; { } x1 := y * 10 + p; { } Writeln(' : ', x1); Repeat until keypressed; End. Program Talhro; { , . 0, 1 2 0, 3, 4, 5, 6 7 5 8 9 0 10 } Uses Crt; Var m, p, y : Longint; Begin Clrscr; Writeln(' : '); Readln(m); p := m div 10; { } y := m mod 10; { } { y p y, . 156967, y 7 p 15696 } If y 2) and (y < 8) then m := p * 10 + 5; { 15696 * 10 + 5 = 156965 } If y >= 8 then m := p * 10 + 10; { 15696 * 10 + 10 = 156970 } Writeln('O : ', m); Repeat until keypressed; End.

11

/

Pascal

Program Praxis; { (+ - * /) } Uses Crt; Var a, b, r : Real; z : Char; Begin Clrscr; Writeln(' : '); Readln(a, b); Writeln(' : '); Readln(z); Case z of '+' : r := a + b; '-' : r := a - b; '*' : r := a * b; '/' : r := a / b; End; { case } Writeln(' : ', r); Repeat until keypressed; End.

While : Program Twhile; Var metritis : Integer; Begin Clrscr; metritis := 0; { } While metritis < 6 do Begin Writeln(' = ', metritis); metritis := metritis + 2; { 2 } End; { end of while } End. While metritis 6, . 0, 2 4. 6, .

12

/

Pascal

Program Trepeat; Var metritis : Integer; Begin Clrscr; metritis := 0; Repeat Writeln(' = ', metritis); metritis := metritis + 2; Until (metritis > 4); End. Repeat , , . FOR : Program Tfor; Var metritis : Integer; Begin Clrscr; For metritis := 0 to 4 do Writeln(' = ', metritis); End. 0 4 , metritis 0, 1, 2, 3 4. Downto, 4 0, .

Program Ektyposi_Akeraion; { 1 20 } Uses Crt; Var i : Byte; Begin Clrscr; For i := 1 to 20 do Writeln(i); { 20 1 20 } Repeat until keypressed; End.

13

/

Pascal

Program Sum_Product; { } Uses Crt; Var i, N : Byte; x, sum, product : Real; Begin Clrscr; sum := 0; { } product := 1; { 1 } Writeln(' : '); Readln(N); For i := 1 to N do Begin Readln(x); { } sum := sum + x; { } product := product * x; { product } End; { end of for } Writeln(' : ', sum, ' : ', product); Repeat until keypressed; End. Program Max; { } Uses Crt; Var i, N : Byte; x, max : Real; Begin Clrscr; Writeln(' : '); Readln(N); Readln(x); { 1 } max := x; { } For i := 1 to N-1 do { -1 } Begin Readln(x); { } { max , max } If x > max then max := x; End; { end of for } Writeln(' : ', max); Repeat until keypressed; End.

14

/

Pascal

Program Pos_Zero_Neg; { , } Uses Crt; Var i, N, pos, zer, neg : Byte; x : Real; Begin Clrscr; Writeln(' : '); Readln(N); pos := 0; { } zer := 0; { } neg := 0; { } For i := 1 to N do Begin Readln(x); { } { , pos } If x > 0 then pos := pos + 1; { , zer } If x = 0 then zer := zer + 1; { , neg } If x < 0 then neg := neg + 1; End; { end of for } Writeln(' : ', pos); Writeln(' : ', zer); Writeln(' : ', neg); Repeat until keypressed; End.

15

/

Pascal

Program Mathites; { , A, B, C } Uses Crt; Var i, N, b, sa, sb, sc, mo_a, mo_b, mo_c : Byte; sa_b, sb_b, sc_b : Integer; onoma : String; taxi : Char; Begin Clrscr; Writeln(' : '); Readln(N); sa := 0; { } sb := 0; { } sc := 0; { C } sa_b : = 0; { } sb_b := 0; { } sc_b := 0; { C } For i := 1 to N do Begin Writeln(' , : '); Readln(onoma, b, taxi); If taxi = 'A' then { } Begin sa := sa + 1; sa_b := sa_b +b; End; If taxi = 'B' then { } Begin sb := sb + 1; sb_b := sb_b +b; End; If taxi = 'C' then { C } Begin sc := sc + 1; sc_b := sc_b +b; End; End; { end of for } mo_a := sa_b/sa; { } mo_b := sb_b/sb; { } mo_c := sc_b/sc; { C } Writeln(' : ', sa, mo_a, sb, mo_b, sc, mo_c); Repeat until keypressed; End.

16

/

Pascal

17

/

Pascal

Program ReadKey_Test2; { ReadKey , ascii Esc, ascii 27 } Uses crt; Var Key : Char; Begin Repeat Key := ReadKey; Writeln(' ', Key, ' : ', Ord(Key)); Until Ord(Key)=27; Repeat Until KeyPressed; End. Program Strs; { Pascal string string, - string ' } Uses crt; Var Symbola : String; Begin ClrScr; Write(' : ');Read(Symbola); WriteLn; { } WriteLn(' '); WriteLn( '=============================='); WriteLn('Symbola - : ', Symbola); WriteLn('Length - :', Length(Symbola); WriteLn('Symbola[1] - 1 : ', Symbola[1]); WriteLn('Ord - ascii 1 : ', Ord(Symbola[1]); WriteLn('Succ - 1 : ', Symbola[succ(1)]); WriteLn('Pred - 4 : , Symbola[pred(4)]); WriteLn; { } Repeat Until KeyPressed; End.

18

/

Pascal

Program Antistrofh; { } Uses crt; Var x, x1 : Integer; p1, p2, y1, y2 : Byte; Begin Clrscr; Repeat Writeln(' : '); Readln (x); Until (x>=100) and (x= 50 { 50 } Then n := p*100 + 100; Writeln(' : ', n); Repeat until keypressed; End. Program mhden_2; { , 100, real, 0.5 100 } Uses crt; Var k, n : Longint; p : Real; Begin Clrscr; Writeln(' : '); Readln(k); p := k/100; { 100 } n := int(p+0.5); { } n := n*100; { 100 } Writeln(' : ', n); Repeat until keypressed; End.

21

/

Pascal

Program ypallhloi; { , : , (1=, 2=, 3=) - } Uses crt; Var age, min1, min2, min3, N, i : Byte; onoma : String; category : Char; Begin Clrscr; Writeln(' : '); Readln(N); min1 := 100; { } min2 := 100; { } min3 := 100; { } For i := 1 To N Do Begin Writeln(' , : '); Readln(onoma); Readln(category); Readln(age); Case category of '1' : If age < min1 then min1 := age; '2' : If age < min2 then min2 := age; '3' : If age < min3 then min3 := age; end; { Case } End; { For } Writeln(' 1 : ', min1); Writeln(' 2 : ', min2); Writeln(' 3 : ', min3); Repeat until keypressed; End.

22

/

Pascal

Program fylo; { : (1=, 2=) - } Uses crt; Var onoma : String; fylo : Char; sum_a, sum_g, N, i : Byte; Begin Clrscr; Writeln(' : '); Readln(N); sum_a := 0; { } sum_g := 0; { } For i := 1 To N Do Begin Writeln(' & : ');Readln(onoma);Readln(fylo); Case fylo of '1' : sum_g := sum_g + 1; '2' : sum_a := sum_a + 1; End; { Case } End; { For } Writeln(' : ', sum_g); Writeln(' : ', sum_a); Repeat until keypressed; End. Program N_arithmoi; { , } Uses crt; Var N, i : Byte; sum, product, m_o, number : Longint; Begin Clrscr; Writeln(' : '); Readln(N); sum := 0; { } product := 1; { } For i := 1 To N Do Begin Writeln(' : '); Readln(number); sum : = sum + number; product := product * number; End; { For } m_o := sum/N; { } Writeln(' : ', sum); Writeln(' : ', product); Writeln(' : ', m_o:10:2); Repeat until keypressed; End.

23

/

Pascal

Program Eidh; { - , } Uses crt; Bar i, N : Byte; max : Longint; onoma_max : String[30]; onomasia : array[1..50] of String[30]; timh : array[1..50] of Longint; Begin Clrscr; Writeln(' : '); Readln(N); { } { } For i:=1 to N Do Begin Writeln(' : '); Readln(onomasia[i]); Writeln(' : '); Readln(timh[i]); End; { For } { } { } max := timh[1]; onoma_max := onomasia[1]; For i:=2 To N Do Begin If timh[i] > max Then Begin max := timh[i]; onoma_max := onomasia[i]; End;{ If } End;{ For } Writeln(' : ',onoma_max,' ', max, ' .'); Repeat until keypressed; End.

24

/

Pascal

Program Thleorash; { : . ( 20 ) . ( 8 20 ) . ( 8 ) 30 } Uses crt; Var i, hours, category_1, category_2, caterogy_3 : Byte; Begin Clrscr; category_1 := 0; { } category_2 := 0; caterogy_3 := 0; For i:=1 to 30 Do Begin Writeln(' : '); Readln(hours); Case hours of 0..7 : category_1 := category_1 + 1; 8..20 : category_2 := category_2 + 1; 21..255: category_3 := category_3 + 1; End;{ Case } End; { For } Writeln(' : ', category_1, category_2, category_3); Repeat until keypressed; End. Program Athroisma_Pinaka; { } Uses crt; Var i, N : Byte; sum : Longint; pinakas : Array[1..100] of Integer; Begin Clrscr; Writeln(' : '); Readln(N); sum := 0; { } For i:=1 To N Do Begin Writeln(' : '); Readln(pinakas[i]); End; { For } For i:=1 To N Do sum := sum + pinakas[i]; Writeln(' : ', sum); Repeat until keypressed; End.

25

/

Pascal

Program Athlites; { 10 6 - - } Uses crt; Var i, j : Byte; max_oliko : Real; { } max : Real; { } onoma_max : String[30]; { } onoma : array[1..10] of String[30]; { } epidoseis : Array[1..10, 1..6] of Real; { } Begin Clrscr; max_oliko := 0.0; { } For i:=1 to 10 Do Begin Writeln(' ', i, ' : '); Readln(onoma[i]); max := 0.0; { } For j:=1 to 6 Do Begin Writeln(' ', j, ' : '); Readln(epidoseis[i, j]); If epidoseis[i, j] > max Then max := epidoseis[i, j]; { } If epidoseis[i, j] > max_oliko Then Begin { } max_oliko := epidoseis[i, j]; onoma_max := onoma[i]; End;{ If } End; { For-j } Writeln(' : ',max); End;{ For-i } Writeln(' : ', max_oliko, ' : ', onoma_max); Repeat until keypressed; End.

26

/

Pascal

Program Mathites; { 20 : . . (1=, 2=) . } Uses crt; Var i : Byte; max_bathmos, min_bathmos : Byte; onoma_max, onoma_min : String[30]; onoma : array[1..20] of String[30]; fylo, bathmos : Array[1..20] of Byte; Begin Clrscr; { } For i:=1 To 20 Do Begin Writeln(' : '); Readln(onoma[i]); Writeln(' : '); Readln(fylo[i]); Writeln(' : '); Readln(bathmos[i]); End; { For } max_bathmos := 0; { } min_bathmos := 21; { } For i:=1 To 20 Do Begin Case fylo[i] of 1 : If bathmos[i] < min_bathmos Then Begin min_bathmos := bathmos[i]; onoma_min := onomasia[i]; End;{ If } 2 : If bathmos[i] > max_bathmos Then Begin max_bathmos := bathmos[i]; onoma_max := onomasia[i]; End;{ If } End;{ Case } Writeln(' : ', max_onoma, ' : ', max_bathmos); Writeln(' : ', min_onoma, ' : ', min_bathmos); Repeat until keypressed; End.

27

/

Pascal

Program Max_Pinaka; { } Uses crt; Var i, N, thesi : Byte; sum : Longint; max : Integer; pinakas : Array[1..100] of Integer; Begin Clrscr; Writeln(' : '); Readln(N); { } For i:=1 To N Do Begin Writeln(' : '); Readln(pinakas[i]); End; { For } { } { } max := pinakas[1]; thesi := 1; For i:=2 To N Do If pinakas[i] > max Then Begin max := pinakas[i]; thesi := i; End;{ If } Writeln(' : ', max,' : ', thesi); Repeat until keypressed; End.

28

/

Pascal

Program Bathmoi_Mathiton; { } Uses crt; Var i, N : Byte; max : Byte; max_onoma : String[30]; bathmos : Array[1..100] of Byte; onoma : Array[1..100] of String[30]; Begin Clrscr; Writeln(' : '); Readln(N); { } { } For i:=1 To N Do Begin Writeln(' : '); Readln(onoma[i]); Writeln(' : '); Readln(bathmos[i]); End; { For } { } { } max := bathmos[1]; max_onoma := onoma[1]; For i:=2 to N Do If bathmos[i] > max Then Begin max := bathmos[i]; max_onoma := onoma[i]; End;{ If } Writeln(' : ', max_onoma,' : ', max); Repeat until keypressed; End.

29

/

Pascal

Program Men_Women; { : , , (1 = , 2 = ), , - 60 1.80, 85 40 } Uses crt; Var i, N, g60, i180, i85, i40, mo_gyn, fylo, ypsos, baros, age : Byte; sum_age : Integer; onoma : String[30]; Begin Clrscr; Writeln(' : '); Readln(); sum_age:=0; g60:=0; i180:=0; i85:=0; i40:=0; { } For i:=1 To N Do Begin Writeln(' : '); Readln(onoma); Repeat Writeln(' : '); Readln(fylo); Until fylo in [1..2]; Writeln(' : '); Readln(ypsos); Writeln(' : '); Readln(baros); Writeln(' : '); Readln(age); { } Case fylo of 1 : If baros>60 Then Begin sum_age := sum_age + age; g60 := g60 + 1; End; { If - Case-1 } 2 : Begin If ypsos > 180 Then i180 := i180 +1; If baros < 85 Then i85 := i85 + 1; If age < 40 Then i40 := i40 + 1; End; { Case-2 } End; { Case } End; { For } { } Writeln(' 60 : ', Round(sum_age/g60)); Writeln(i180, ' 1.80 ', i85,' 85 ',i40,' 40); Repeat until keypressed; End.

30

/

Pascal

Program Taxeis; { (, ) (, C) } Uses crt; Var a_onoma : array[1..100] of String; { . } b_onoma : array[1..100] of String; { . } c_onoma : array[1..100] of String; { . C } a_bathmos : array[1..100] of Byte; { . } b_bathmos : array[1..100] of Byte; { . B } c_bathmos : array[1..100] of Byte; { . C } onoma : String; i, N, ia, ib, ic, bathmos : Byte; taxi : Char; Begin Clrscr; Writeln(' : '); Readln(N); ia := 0; { } ib := 0; { } ic := 0; { } For i:=1 To N Do Begin Writeln(' : '); Readln(onoma); Writeln(' : '); Readln(bathmos); Repeat Writeln(' : '); Readln(taxi) Until taxi In ['a', 'b', 'c']; { a, b c } { } Case taxi of 'a' : Begin ia := ia+1; { } a_onoma[ia] := onoma; a_bathmos[ia] := bathmos; End; { Case-a } 'b' : Begin ib := ib+1; b_onoma[ib] := onoma; b_bathmos[ib] := bathmos; End; { Case-b }

31

/

Pascal

'c' : begin ic := ic+1; c_onoma[ic] := onoma; c_bathmos[ic] := bathmos; End;{ Case-c } End; { Case } End; { For } { A, B C } Writeln(' :'); For i:=1 To ia Do Writeln(i, '. ', a_onoma[i], ' ', a_bathmos[i]); Writeln(' B :'); For i:=1 To ib Do writeln(i, '. ', b_onoma[i], ' ', b_bathmos[i]); Writeln(' C :'); For i:=1 To ic Do Writeln(i, '. ', c_onoma[i], ' ', c_bathmos[i]); Repeat until keypressed; End.

32

/

Pascal

Program Molinsi; { 0 100 20 , . - } Uses crt; Var molinsi : Array[1..20] of byte; i : Byte; Begin Clrscr; { } { 0 100 } For i:=1 To 20 Do Begin Repeat Writeln(' ', i, ' : '); Readln(molinsi[i]); Until molinsi[i] in [0..100]; End; { For } { i } { } { } For i:=2 To 19 Do If (molinsi[i]>molinsi[i+1]) and (molinsi[i]>molinsi[i-1]) Then Writeln(' ',i,' ',molinsi[i]); { } For i:=1 To 20 Do Write(molinsi[i], ' '); Repeat until keypressed; End.

33

/

Pascal

Program Ptiseis; { - - - } Uses crt; Const max_load = 100;{ 100 } Var i, weight, ptisi, sum : Byte; Begin Clrscr; sum := 0; ptisi := 0; { } For i:=1 To 20 Do Begin { 20 } Writeln(' : '); Readln(weight); sum := sum + weight; { } If sum > max_load Then Begin { } ptisi := ptisi + 1; { } sum := sum - weight; { } Writeln(' ', ptisi, ' ', sum); sum := weight; { sum } End; { If } If sum = max_load Then Begin { } ptisi := ptisi + 1; { } Writeln(' ', ptisi,' ', sum); sum := 0; { sum } End;{ If } End; { For } If sum>0 Then Do Begin { } ptisi := ptisi + 1; { } Writeln(' ', ptisi, ' ', sum); End;{ If } Repeat until keypressed; End.

34

/

Pascal

Program Taxinomisi_Pinaka; { - Bubble-Sort , 1 flag - flag , } Uses crt; Var a : Array[1..100] of Integer; temp : Integer; i, N, flag : Byte; Begin Clrscr; Writeln(' : '); Readln(N); { } For i:=1 To N Do Begin Writeln(' ', i, ' : '); Readln(a[i]); End; { For } { } Repeat flag := 0; { flag } For i:=1 To N-1 Do Begin If a[i] > a[i+1] Then Begin { } temp := a[i]; a[i] := a[i+1]; a[i+1] := temp; flag := 1; { flag 1 } End; { If } End; { For } Until flag = 0; { flag 0, } { } { } For i:=1 To N Do Begin Writeln(' ', i, ' : , a[i]); End; { For } Repeat until keypressed; End.

35

/

Pascal

Program Athroisma_Pinaka; { } Uses crt; Var i, j, n, m : Byte; sum : Longint; a : Array[1..100, 1..100] of Integer; Begin Clrscr; Writeln(' : '); Readln(n); Writeln(' M : '); Readln(m); { } sum := 0; { } For i:=1 To n Do Begin { } For j:=1 To m Do Begin { } Writeln(' : ', i, ', ', j); Readln(a[i, j]); sum := sum + a[i, j]; End; { For-j } End; { For-i } { } Writeln(' : ', sum); Repeat until keypressed; End.

36

/

Pascal

Program Max_Pinaka; { } Uses crt; Var i, j, n, m : Byte; max : Integer; a : Array[1..100, 1..100] of Integer; Begin Clrscr; Writeln(' : '); Readln(n); Writeln(' : '); Readln(m); { } For i:=1 To n Do Begin For j:=1 To m Do Begin Writeln(' : ', i ,' ,' , j); Readln(a[i, j]); End; { For-j } End; { For-i } { max 1,1 } max := a[1,1]; { } For i:=1 To n Do Begin For j:=1 To m Do Begin If a[i, j]) > max Then max := a[i, j]; End; { for-j } End; { for-i } { } Writeln(' : ', max); Repeat until keypressed; End.

37

/

Pascal

Program Athroisma_Grammhs_Pinaka; { () () } Uses crt; Var i, j, n, m : Byte; sum : Longint; a : Array[1..100, 1..100] of Integer; b : Array[1..100] of Longint; Begin Clrscr; Writeln(' : '); Readln(n); Writeln(' : '); Readln(m); { } For i:=1 To n Do Begin For j:=1 To m Do Begin Writeln(' : ', i, ' ,', j); Readln(a[i, j]); End;{ For-j } End; { For-i } { } { } For i:=1 To n Do Begin sum := 0; { } { } For j:=1 To m Do Begin sum := sum + a[i, j]; End; { For-j } b[i] := sum; { i i } { } End; { For-i } Repeat until keypressed; End.

38

/

Pascal

Program Thetikoi_Arnitikoi; { () } Uses crt; Var i, j, n, m, pos, neg : Byte; a : Array[1..100, 1..100] of Integer; Begin Clrscr; Writeln(' : '); Readln(n); Writeln(' : '); Readln(m); { } For i:=1 To n Do Begin For j:=1 To m Do Begin Writeln(' : ', i, ',', j);readln(a[i, j]); End; { For-j } End; { For-i } { } For i:=1 To n Do Begin pos := 0; neg := 0; { } { } For j:=1 To m Do Begin If a[i, j] > 0 Then pos := pos + 1; If a[i, j] < 0 Then neg := neg +1 ; End; { For-j } { } Writeln(' ', i, ' ', pos, ' ', neg, ' ); End; { For-i } Repeat until keypressed; End.

39

/

Pascal

Program Eteria; { - - , , } Uses crt; Var polisis : Array[1..6, 1..4] of Longint; max : Longint; i, j, i_max, j_max : Byte; Begin Clrscr; { } { 6 4 } For i:=1 To 6 Do Begin For j:=1 To 4 Do Begin Writeln(' ', j, ' ', i, ' : '); Readln(polisis[i, j]); End; { For-j } End; { For-i } { } For i:=1 To 6 Do Begin Writeln(' ', i, ' : '); Writeln('-----------------------------------------------------------------'); For j:=1 To 4 Do Begin Write(j, ' : '); Writeln(polisis[i, j]); End; { For-j } Writeln; End; { For-i } max := polisis[1,1]; i_max := 1; j_max := 1; { max 1 } { . 1 . } For i:=1 To 6 Do Begin For j:=1 To 4 Do Begin If polisis[i,j] > max Then Begin max := polisis[i, j]; i_max := i; j_max := j; End; { If } End; { For-j } End; { For-i } { } Writeln(' ', max, ' ', i_max, ' , ', j_max, ' '); Repeat until keypressed; End.

40

/

Pascal

Program Oplites; { 20 : (1= , 2=, 3=) - } Uses crt; Var i, i_stratos, i_aeroporia, i_nautiko, oplo : Byte; name : String[30]; stratos, aeroporia, nautiko : Array[1..20] of String[30]; Begin Clrscr; i_stratos :=0; { } i_aeroporia := 0; i_nautiko :=0; { } For i:=1 To 20 Do Begin Writeln(' : '); Readln(name); Repeat Writeln(' : '); Readln(oplo); Until oplo in [1..3]; Case oplo of 1 : Begin i_stratos := i_stratos + 1; stratos[i_stratos] := name; End; { Case-1 } 2 : Begin i_aeroporia := i_aeroporia + 1; aeroporia[i_aeroporia] := name; End; { Case-2 } 3 : Begin i_nautiko := i_nautiko + 1; nautiko[i_nautiko] := name; End; { Case-3 } End; { Case } End; { For } { } Writeln(' : '); For i:=1 To i_stratos Do Writeln(stratos[i]); Writeln; Writeln(' : '); For i:=1 tTo i_aeroporia Do writeln(aeroporia[i]); Writeln; Writeln(' : '); For i:=1 To i_nautiko Do Writeln(nautiko[i]); Repeat until keypressed; End.

41

/

Pascal

. Program Center; Uses crt; Var row : Byte; title : String; Procedure center_line(message : String; line : Byte); Begin GotoXY(40 - Length(message) div 2, line); Writeln(message); End; Begin { } row := 2; title := ' .'; Clrscr; center_line(title, row); { } center_line('--------', row+1); center_line('Borland Turbo Pascal !', row+2); End. : ------Borland Turbo Pascal !

42

/

Pascal

, . .. 6 1*2*3*4*5*6. Program local_variables; Var num : Byte; Procedure factor(value : Byte); Var factorial : Real; count : Byte; Begin factorial := 1.0; For count := 1 To value Do factorial := factorial * count; Write(' ', value,' : ' ); Writeln(factorial); End; { Factor } Begin { } Write(' 34 : '); Readln(num); Factor(num); End. { } : 34 : 5 5 : 1.200000000+02

43

/

Pascal

: Program byvalue; Var global_var : Integer; Procedure proc(local_var : Integer); Begin Writeln(' = ', local_var); local_var := 333; Writeln(' = ', local_var); End; Begin { } global_var := 5; proc(global_var); Writeln(' = ', global_var); End. : T = 5 T = 333 K = 5 global_var local_var.

44

/

Pascal

( ): Program byref; Var var, var2 : Integer; Procedure swap_vars(Var var1 : Integer; Var var2 : Integer); Var temp : Integer; Begin temp := var1; var1 := var2; var2 := temp; End; Begin var1 := 55; var2 := 99; Writeln('1 = ', var1, '2 = ', var2); swap_vars(var1, var2); Writeln('1 = ', var1, '2 = ', var2); End. : 1 = 55 1 = 99 2 = 99 2 = 55

, . . , : swap_vars(global_1, global_2); : swap_vars(55, 99);

45

/

Pascal

. Program Funct; Var num, expo, powr : Real; Function power(base, exponent : Real) : Real; Begin If base >0 Then Power := Exp(exponent * Ln(base)) Else Power := -1.0; End; { end of power() } Begin Writeln(' : '); Readln(num); Writeln(' : '); Readln(expo); powr := Power(num, expo); Writeln(num, '', expo, ' = ', powr); End. Funct , power, .

46

/

Pascal

: Program Hideproc; Var globl : Integer; Procedure proc(p_parm : Integer); Var p_locl : Integer; Procedure hidden(hidn_parm : Integer); Var hidn_locl : Integer; Begin Writeln(' hidden : globl, p_parm, p_locl, hidn_parm, hidn_locl'); End; { hidden } Begin Writeln(' proc : globl, p_parm, p_locl'); hidden(44); End; { proc } Begin { } Writeln(' : globl'); proc(99); End. : : globl proc : globl, p_parm, p_locl hidden : globl, p_parm, p_locl, hidn_parm, hidn_locl , proc hidden. hidden proc, . , . hidden, . hidden , proc . proc . . .

47

/

Pascal

factor : Program Recurse; Uses crt; Var num : Byte; result : Real; Function Factor(value : Byte ) : Real; Begin If value > 1 Then factor := value * factor(value-1) Else factor := 1.0; End; { Factor } Begin { } Write(' : '); Readln(num); result := Factor(num); Write(' ', num, ' : '); Writeln(result); End. , : factor := value * factor(value-1) If . .

48

/

Pascal

: , . , case , : Program testfile; Uses Crt; Var datafile : Text; FileName : String; i, epil : Integer; flag : Boolean; Procedure Menu; Begin ClrScr; epil := 0; GotoXY(30,4);Writeln(' '); GotoXY(31,6);Writeln('1. '); GotoXY(31,7);Writeln('2. '); GotoXY(31,8);Writeln('3. '); GotoXY(31,9);Writeln('4. '); GotoXY(28,12);Writeln(' : '); Readln(epil); End; { Menu } Procedure Selection; Begin Case epil of 1 : FileName := 'RAN_DATA.DAT' 2 : Filename := 'CON'; 3 : FileName := 'PRN'; End; { Case } End; { Selection } Begin { } Repeat Menu; flag := True; While (epil>0) and (epil