Function ():;
Begin
End;
Funksiyaning protseduradan farqi, unga murojat qilinganda natija faqat bitta bo‘lib, u shu funksiya nomiga uzatiladi.
Misol 1. Quyidagi hisoblashni funksiyani ishlatgan holda dasturini tuzing.
Program Kol;
Var ncm:Real; n,m,i: Integer;
Function Fact (k: Integer): Integer;
Var P,i: Integer;
Begin
P:=1; For i:=1 to k do P:=P*i;
Fact:=P;
End;
Begin
Read(n,m); l:=n-m; ncm:=Fact(n)/Fact(m)/Fact(i);
Write(‘ncm=’,ncm);
End.
Misol 2. Quyidagi hisoblashni protsedurani ishlatgan holda dastursini tuzing.
Program Fun1;
Var a,b,z,c,d,t1,t2,t3: Real;
Procedure Th(Var x,r: Real);
Var c: Real;
Begin c:=exp(2.0*x); r:=(c-1)/(c+1); End;
Begin
Read(a,b);
th(a,t1); c:=a-b; th(c,t2);
d:=Sqr(a)-Sqr(b); th(d,t3);
z:=(t1+Sqr(t2))/Sqrt(t3);
Write(‘z=’,z:10:3);
End.
Do'stlaringiz bilan baham: |