begin
y:=exp(cos(x))+ ln(x+ 4)/ln(c);
x:=x+h;
write(y);
382
end;
end.
P rogram takrorS (input, output);
var
x,a ,b ,h ,c,y: real;
begin
read(a, b,h,c);
x: =a;
repeat
y:= exp (cos(x))+ ln(x+ 4)/ln (c);
x:= x+ h;
w rite(y);
until x> b;
end.
E ndi shartli o p erato r ham da sikl o p erato rlari y o r
dam ida b a ’zi m asalalarn i yechish usullarini k o ‘ram iz.
13.5. A L G E B R A IK TEN G LA M A LA R N I
Y E C H ISH N IN G TA Q RIBIY U SU LLA RI
A lg eb raik te n g lam a lar ildizini taq rib iy h iso b lash
uchun b ir n ech ta u su llar m avjud, y a ’ni v a ta rla r usuli,
kesm ani ten g ikkiga b o ‘lish usuli, oddiy iteratsiy a usuli
v a boshqalar.
B iz asosan od d iy iteratsiya usuli bilan tan ish ib
chiqam iz.
B izg a
f(x )= 0
te n g lam a berilgan b o ‘lib,
(a,b)
oraliq-
da y ag o n a ildizi m a v ju d b o ‘lsin. T en g lam an in g ildizini
oddiy iteratsiy a usuli bilan
e
aniqlikda h iso b la sh algo rit-
m i q uy id ag ich a b o ‘ladi.
^
1. Ild izn in g b o s h la n g ic h qiym atini ta n lab olam iz:
x0 e(a,b);
2 .f(x )= 0
ten g lam an i
x=(p(x)
k o ‘rinish ga k eltiram iz,
bu y erd a |^'(л
-)|<1
shart bajarilishi lozim;
3.
x k+\
=
(p(xk)
fo rm u la bilan
xk
ketm a-ketlikn i tash
kil etam iz;
383
4.
A gar
k=n
da
\xM - x k\
shart b ajarilsa
x= xk t
qiym at
f(x)= 0
tenglam aning
e
aniqlikdagi taq rib iy ildizi
deb yuritiladi.
6-m isol.
x-tgx=0
tenglam aning eng k ich ik m u sb at
ildizini topish dasturini tuzing,
s
=10"5 aniqlikda.
Program tenglama(input,output);
const PI= 3.141592653;
var x0,xl,x2,eps . real;
begin
read(xO,eps);
repeat
x2:=x0;
x l :=arctan(xO)+PI;
xO :=xl;
until ab s(x 2 -x l) < eps;
w rite(x l,x 2 )
end.
13.6. BERILGAN SONLARNI TA RTIBLASH GA
D O IR M ISO LLAR
1-m isol. B erilgan uchta
a,b
v a
с
so n lam in g eng
kattasini toping. 13.4-rasm da m asalaning blo k-sx em asi
keltirilgan.
Program тахЗ(input, output);
label 10,20;
var a,b,c: real;
begin
w riteln(’uchta son kiritin g );
readln(a,b,c);
i f a>b then goto 10 else
ifb < c then
begin
writeln(c); goto 20;
384
end else
begin
writeln(b); goto 20; end;
10: i f a< c then writeln(c)
else writeln(a);
20
:
end.
( b o s h )
Z3l7
Y o ’q
H a
a> b
H a
H a
b < c
a < c
1 3 . 4 - r a s m .
2-m isol. B erilg an ik kita sonni o ‘sish ta rtib id a
jo y lash tirish g a d astu r tu z in g .
а
b
b erilg an so n lar b o ‘lsin,
h
q o ‘sh im c h a o ‘z-
garuvchi k iritam iz. A g a r
a
sh art bajarilsa
а
b
b o s
m aga chiq arilad i, ak s h o ld a
h=a, a=b, b=h
alm ash tirish -
lam i bajarib,
a va b
n in g q iym atini bosm ag a chiqaram iz
(13.5 -rasm ). D a stu m in g k o ‘rinishi:
Program tart2 (input, output);
label 10;
var a,b,h: real;
begin
385
w riteln(’ikki son kiritin g );
readln(a.b);
i f a<=b then goto 10
else begin h:=a; a:=b; b:=h; end;
10: writeln(a,b);
end.
С
bosh )
Ha
aY o‘q
h=a
a=b
b=h
С ta m o m )
1 3 .5 - r a s m .
3-m isol. B erilgan uchta
a,b,c
sonning eng kattasini
toping.
U shbu m asalani yechishda dastlab
a va b
sonlari
taqqoslaniladi, ulam ing kattasini
b
deb o lam iz (agar
b
soni katta b o im a s a
b=a
alm ashtirish bajariladi). K eyin
esa 6с
bo sm ag a
chiqariladi, aks holda
c=b
alm ashtirish bajariladi (13.6-
rasm ). D astum ing k o ‘rinishi:
Program maxt3(input, output);
label 10,20;
386
var a,b,c: real;
begin
w riteln (’uchta son k iritin g );
readln(a,b,c);
i f a<=b then goto 10
else b:=a;
10: ifb < = c then goto 20
else c: =a;
20: writeln(c:8:3); end.
С
B o s h )
/
a ,b ,c
/
H a
a < b
Y o ‘q
b = a
H a
b < c
Y o ‘q
c = b
Q
ta rn o m 3
1 3 . 6 - r a s m .
4-misol. Berilgan uchta
а ,Ь \г.с
sonlami bosmaga tartib-
langan ko‘rinishda chiqaring.
Bu misolni yechishda dastlab a va 6 sonlari taqqoslanadi,
ulaming kattasini
b
deb olamiz (agar
b
soni katta bo‘lmasa
b=a
almashtirish bajariladi). Keyin
esab
shart tekshiriladi,
agar shart bajarilsa
s
bosmaga chiqariladi, aks holda
s=b
al
mashtirish bajariladi (13.7-rasm). Dastur ko‘rinishi:
387
Program tart3 (input, output);
label 10,20,30;
var a, b,c,h: real;
begin
w riteln(’uchta son kiriting);
readln(a,b,c);
i f a<=b then goto 10
else
begin h:=a; a:=b; b:=h; end;
10: i f a<=c then goto 20
else
begin h:=a; a:=c; c:=h; end;
20: ifb < = c then goto 30
else
begin h:=b; b:=c; c:=h; end;
30: writeln(a,b,c);
end.
H a
a < b
Y o 'q
h = a
a = b
h=h
H a
a < c
Y o 'q
h = a
a = c
c = h
H a
b < c
Y o 'q
h = b
b = c
c = h
a .b .c
С
ta rn o m
)
13.7-rasm .
13.7. ANIQ IN TEGRALNING QIYM ATINI
HISOBLASHNING SONLI USULLARI
1-m isol. f
f(x )d x -
integralning qiym atini
(a,b)
oraliqni
n
ta boN akka ajratib to ‘g ‘rito ‘rtb urch ak lar usuli
yordam ida hisoblang.
3 8 8
T o ^ 'rito 'rtb u rc h a k la r usuli. h=
q ad am hisob-
n
lanadi. In teg raln in g taq rib iy qiym ati 5, = X /(* )/?, bun da
/•I
X' = a + ( i - \ ) h
fo rm u la b ilan hisoblanadi. D astu rn i ushb u
f ( x )
= V ? ,
a = l, b=2, n= 20
hoi uchun k eltiram iz.
program in ti (input, output);
label 10;
var a,b ,n,i,sl,h ,x: real;
begin
w riteln (’a ning qiym atini kirittng: \a); readln(a);
w riteln (’b n ing qiym atini kiriting: \b ); readln(b);
w rite ln f’n n ing qiym atini kiriting: \n ); readln(n);
sl:= 0 ; x:= a; h:=(b-a)/n; i:= l;
10: sl:= sl+ exp (2 * ln (x)/3 );
ifi< n then
begin
i:= i+ l; x := x+ (i-l)* h ; goto 10;
end;
w riteln (’integralning taqribiy qiym ati
=
\s l) ;
end.
2 -m iso l. J*
f [ x ) d x
integralnin g q iym atini
(a,b)
oraliqni
n
ta o raliq q a b o ‘lib, trap etsiy alar usu li y o rd am i
da hisoblang.
Trapetsiyalar usuli.
л = -^—^ qadam v a
y i
= /(лгД
n
лг; = a +
X\
= a
, =
b -
q iy m atlar hiso blan adi.
Integralning taq rib iy qiym ati
=/(4
y n
=
f ( b )
fo rm u la bilan hisoblanadi.
389
M asala algoritm ining blok-sxem asi 21 -chizm ada
keltirilgan. D asturni ushbu /( * ) =
v a t
+100 hoi uchun
keltiram iz.
program int2 (input, output);
label 10;
var a,b,n,i,sl,h,x: real;
begin
readln(a,b,n);
sl:= 0; x:=a; h:=(b-a)/n; i:= l;
10: sl:= sl+ sqrt(sqr(x)+ 100) +sqrt(sqr(x+h)
+ 100)/2;
i f i
begin
i:= i+ l; x:=x+h; goto 10;
end;
S l:= S l* h ;
w riteln(’S l: = \S1);
end.
13.8. BIR 0 ‘LC H O V LI M ASSIVLAR
Paskal algoritm ik tilida m assivlar dastum ing o ‘zga-
ruvchilarini ifodalash qism ida alohida k o ‘rsatilishi lozim.
M assivlam i Paskal algoritm ik tilida ifodalash uchun m ax
sus
array
kalit so ‘zidan foydalanam iz. B ir o ‘lchovli m as
sivlam i dasturda ifodalash quyidagicha bajariladi:
a: array [n..m] o f t;
bunda
- a
- m a s s iv nomi;
- 77 va m - m assiv elem entlari ind ekslarining eng
kichik va eng katta qiym atlari;
- 1
- m assiv elem entlarining tipi.
Indeks qiym atlarining o ‘zg arish o ra lig ‘ini butun son
lar bilan yoki o ‘zgarm aslar nom i bilan ifodalash m um -
390
kin. M isol uchun elem entlar soni 50 ta haqiqiy sondan
iborat boMgan bir o ‘lchovli massivni ikki xil usul bilan
ifodalash mumkin:
1) var a:array [1..50] o f real;
2
) const nm ax:=50;
var a.arra y [L .n m a xJ o f real;
1-misol. Berilgan bir o‘lchovli m assivning elem ent
lari qiym atini kiritish va elem entlar y ig ‘indisini hisob-
lashga dastur tuzing.
x - m assiv nom i,
nm ax
-m a ssiv elem entlari soni,
I -m a ssiv elem enti indeksi.
s
bilan
x(nm ax)
m assiv ele
m entlari y ig ‘indisini belgilaymiz. D asturni ikki xil
k o ‘rinishda yozish mumkin.
1
-k o ‘rinish:
program m ass (input, output);
const nm ax=15;
var i: integer;
s: real;
x: a rra y[L .nm ax] o f real;
begin
s:=0;
f o r i:= l to nm ax do readln(x[i]);
fo r i:= l to nm ax do s:=s+x[i];
w rite ln (,s = ’,s:5);
end.
2-ko ‘rinish:
program m iss (input, output);
const nmax=10;
var i: integer;
s: real;
x: arra y[l..n m a x] o f real;
begin
s:=0;
f o r i:= l to nm ax do
391
begin
readln(x[i]);
s:=s+x[i];
end;
w riteln(’s= \s:8:2);
end.
2-misol. Haqiqiy
a(n), n
m assivning barcha
musbat elementlarining o‘rta arifmetigini hisoblang.
Belgilashlami kiritamiz.
i
- massiv elementlari
indesklarining qiymatlarini aniqlovchi o'zgaruvchi,
i= l,2,..k (к
- massiv elementlari soni,
к<15), S
va
kn
mos ravishda musbat elem entlam ing o ‘rta arifmatik qiy
mati va ulaming soni.
a[i]>0
shart bajarilsa
S= S+ afi],
kn=kn+l
yigNndi hisoblanishi kerak. Ushbu y ig ‘indini
hisoblash tugagandan keyin
S=S/kn
hisoblanadi, y a ’ni
musbat elementlar yig'indisi musbat elem entlar soniga
bo‘linadi. Agar
kn=0
bo ‘lsa, m assivning musbat ele
mentlari mavjud emas.
program urtarif (input, output);
label 10;
const n=15;
var i,k,kn: integer;
s: real;
a: array[l..n] o f real;
begin
readln(k); s:=0; kn:=0;
fo r i:= l to к do readln(a[ij);
fo r i:= l to к do
i f a[i]>0 then
begin
s: =s+a[ij; kn: =kn +1;
end;
i f kn=0 then begin w rite(’musbat elem entlari у о ‘q );
goto 10; end;
392
s:= s/kn; w rite ln (’s= ’,s:8:2);
10: end.
3 -m isol. B ir o ‘lchovli haqiqiy
B(N), n= 20
m as
sivning eng katta elem entini va uning tartib raqam ini
toping.
Belgilashlar:
bm ax
va
imax -B (N )
m assivning eng
katta elem enti va uning tartib raqami;
к
- m assiv ele
m entlari soni b o ‘lsin.
D astlab
b
m assivning barcha elem entlari qiym atini
kiritam iz. M assiv birinchi elementini eng k atta elem ent
deb faraz qilam iz:
bm ax= bl, im a x -1 . i
sikl param etri
2
dan
к
gacha o ‘zgaradi. H ar gal
bt >bmax
shart tekshirila
di, agar bu shart bajarilsa
bm ax=b?
va
im ax= i
alm ashti-
rishlar bajariladi.
program m ax (input, output);
const n=20;
var i,k,imax: integer;
bmax: real;
b: a rra y [l..n ] o f real;
begin
readln(k);
f o r i:= l to к do readln(b[i]);
bmax: = b [l]; im ax:=1;
f o r i:=2 to к do
ifb [i]> b m a x then
begin
bmax: =b[i]; imax: =i;
end;
w rite ln (’bmax= \b m a x:5, ’imax= \im ax);
end.
393
13.9. IK K I 0 ‘L C H 0 V L I M ASSIV LAR
1-misol. Ikki o ‘lchovli haqiqiy
B(N,M )
m assiv m us
bat elementlari yig ‘indisini hisoblashga dastur tuzing
(N<50, M<30).
Belgilashlar:
S
-m assiv elementlari y ig ‘indisi;
k,l
-
mos ravishda massivning satr va ustunlar soni;
n,m -
massiv satr va ustunlarining maksimal soni,
i
-s a tr raqa
mi,
j -
ustun raqami bo‘lsin.
Ikki o ‘lchovli massiv ishtirok etgan masalalarni
yechishda ichma-ich joylashgan sikllam i tashkil qi-
lish maqsadga muvofiqdir. Satr va ustunlam i tashkil qi-
lish uchun
i
va
j
o ‘zgaruvchilami kiritamiz. / tashqi sikl
param etri,у esa ichki sikl parametri bo ‘lishi lozim. / va
j
ning har bir qiymatida
b > 0
shart tekshiriladi, agar shart
bajarilsa
S=S+bi
y ig in d i hisoblanadi. A gar
S=0
bo‘lsa,
massivning mus&at elementlari m avjud emas.
Program musbat(input, output);
const n=50;m=30;
var i,j,k,l: integer;
S.real;
b: array [ l..n ,l..m ] o f real;
begin
readln(k,l);
S:=0;
fo r i:= l to к do
fo r j: = l to I do
begin
readln(b[i,j]);
ifb [ ij] > 0 then S:= S+ b[ij];
end;
w riteln (,S= \S);
i f S=0 then w riteln('m assivning m usbat elem entlari
y o ‘q);
end.
394
2-m isol. H aqiqiy ikki o ‘lchovli m assivning eng kat
ta elementini toping.
Belgilashlar:
b -
m assiv nomi; ,
i=20, j= 1 5 -
mos
ravishda m assivning satrlar va ustunlarining maksimal
soni; & va / esa satr va ustunlar soni.
Dastlab
b
m assivning barcha elem entlari qiym atla
rini kiritamiz. M assiv birinchi elem entini eng katta ele
m ent deb faraz qilamiz:
bm ax= bIJ.
K eyin esa ichma-ich
siklning ichida
bt >bm ax
shart tekshiriladi, agar bu shart
bajarilsa
bm ax= ^i/
alm astirish bajariladi.
Program m ax (input, output);
const n = 2 0 ;m = l5;
var i,j,k,l: integer;
bmax: real;
b : array[1 ..n ,l..m ] o f real;
begin readln(k,l);
fo r i:= l to к do
fo r j : = l to I do readln(b[i,j]);
bmax: =b[1,1];
fo r i:= l to к do
fo r j : = l to I do
ifb[i,j]> b m ax then
bm ax:= b[i,jj;
w riteln (’bm ax= \bm ax);
end.
3-m isol. Ikki o ‘lchovli haqiqiy
B(N,M )
m assivning
bosh diagonalining quyi qism ida joylashgan elem entlari
y ig in d isin i hisoblang
(N<50, M<30).
D astum ing 1-ko‘rinishi:
program diag (input, output);
const n=50;m =30;
var i,j,k,l: integer;
395
S: real;
b: array[1.
o f real;
begin
readln(k,l);
S:=0;
fo r i:=J to к do
fo r j:= ] to I do
begin
readln(b[i,j]); ifi> j then S:=S+b[iJ];
end;
w riteln(’S= \S);
end.
Dastuming 2-ko‘rinishi.
Program diag(input, output);
const n=50;m=30;
var i,j,k,l: integer;
S: real;
b : array [ L .n .L .m ] o f real;
begin
readln(k,l);
S:=0;
fo r i:=J to к do
fo r j : = l to I do
readln(b[ij]);
fo r i:=2 to к do
fo r j: = l to i-1 do
S:=S+b[iJ];
w riteln(’S= \S);
end.
1>
Dostları ilə paylaş: