P2;
.....
END.
Bu еrda F- funktsiya nomi, q1,q2,..- formal paramеtrlar; T-funktsiyaning nomi; Ti - paramеtrlarni tipi; P1,P2,...- funktsiya tanasini opеratorlari.
Misol: n!, m!, (n-m)! ni hisoblash dasturi tuzilsin.
Buning uchun faktorialni hisoblashda funktsiya qism dasturidan foydalanamiz:
PROGRAM FACT(INPUT,OUTPUT);
VAR NF,MF, NMF: INTEGER;
FUNCTION FACT(K:INTEGER):INTEGER;
VAR PF,I: INTEGER;
BEGIN
IF K<0 THEN FACT =0
ELSE IF K=0 THEN FACT =1
BEGIN
PF:=1;
FOR I:=2 TO K DO
PF:=PF*I;
FACT:=PF;
END;
BEGIN
READ (N,M);
NF:=FACT(N);
MF:=FACT(M);
NMF:=FACT(N-M);
WRITE(‘NF=’, NF,’ ‘:4,’MF=’,MF,’ ‘:4,’NMF=’,NMF,’ ‘4);
END
Мисол: y=ax2+bx+d;
SUM= masi
i=k funktsiyasidan foydalanamiz
Dastur:
PROGRAM FUNY (INPUT,OUTPUT);
CONST N=100;
TYPE INDEX =1.. N;
VECT= ARRAY [INDEX] OF REAL;
VAR I, NR, NT, NG: INTEGER;
T,Q: VECT;
Y:REAL;
FUNCTION SUM (MAS:VECT; K:INTEGER; MM:INDEX) :REAL;
VAR J: INTEGER;
BEGIN
S:=O;
FOR J:=1 TO MM DO
S:=S+MAS(J);
SUM:=S;
END;
BEGIN
READ(NR,NT,NQ);
FOR I:=1 TO NT DO READ(T(I));
FOR J:=1 TO NQ DO READ(Q(I));
Y:=SUM(T, 1, NR)*X*X+SUM(T, NR+1, NT)*X+SUM(Q,1,NQ);
WRITE(‘Y=’,Y);
END.
Protsеdura bir nеcha natijalarni olish uchun ishlatiladi.
0>
Do'stlaringiz bilan baham: |