Uchinchi qadam
S2
N + l qadam i
SN
N+2 qadam i
UNTIL (holati)
A lgoritm ning afzalliklari:
A lgoritm ning asosiy afzalliklari quyidagilar:
(I)
Muammoning
bosqichma-bosqich
hal
etishning
oson
tushunish mumkinligi;
(П)
X atoliklar osonlikcha hal etilishi;
(П1)
Dasturlash tillaridan bog‘liq emasligi, ozodligi;
(IV)
Kompyuterga algoritmning har bir bosqichi osonlikcha
kodlanishi va dastum ing yuqori darajadagi kodlashtirish tiliga mos
kelishi.
11.2. SODDA DASTURLARNI ALGORITM LARINI
ISHLAB CHIQISH.
ALGORITM : Ikkita sonni o ‘rnini almashtirish.
Berilgan ikkita son A, B.Biz bu sonlami о ‘m ini almash-
tirishimiz kerak40.
1. INPUT A, В
2. TEM P <- A
A <- В В <- TEMP
3. W rite “Exchanged values are ”, A, В
4. End.
ALGORITM :Uchta sonni ichidan maksimalini topish.
Berilgan uchta son А, В, C. Biz bu sonlami ichidan eng
kattasini topishimiz kerak.
1. INPUT А, В, С
2.
IF
(A >B)
THEN
Begin
IF
(A > C)
THEN
W rite “Biggest number is” , A
ELSE
40 J.B .D ix sit. “ F u n d am en tals o f c o m p u ter p ro g ram m in g an d IT ” 2011. 150 p.
275
Write “Biggest num ber is”, С
End
E L S E
Begin
IF (В > C) T H E N
Write “Biggest num ber is”, В
E L S E
W rite “Biggest num ber is”, С
End
3.
END.
A L G O R IT M : Uchburchakni yuzini topish.
Uchburchakni uchta tom oni berilgan А, В, C. Biz ushbu
uchburchakni yuzini topishimiz kerak. S - perimetr.
1. INPUT A, B ,C
2. IF (((A+B) >C) AND ((B+C) >A) AND ((C+A) > B )) T H E N
Begin
S <- (A + В + C)/2
A rea <- VS x (S - A) x (S - B) x (S - C)
W rite “A rea o f triangle is”, Area, “sq. units”
End
E L S E
W rite “Triangle is not possible”
3. END.
A L G O R IT M : K v a d ra t ten g lam an i ildizini aniqlash.
Kvadrat tenglamani ildizini aniqlash
(Ax2
+ Bx + С = 0)
1. INPUT A, B ,C
2. IF A = 0 T H E N
Begin
IF В = 0 T H E N
Begin
W rite “Equation is degenerate” goto step 5
End
E LSE
Begin
Write “Linear equation has single root”
276
xl = -С/В
W rite “R oot =”, xl
goto step 5
End
End
3 .D = B x B - 4 . 0 x A x C
4. IF D > 0 T H E N
Begin
W rite “Real and distinct roots” xl = (-B + V
d
) / (2.0 X A)
x2 = (-B - VD ) / (2.0 x A)
W rite “First root =”, xl W rite “Second root =”, x2
End
E LSE
Begin
IF (D = 0) T H E N
Begin
W rite “Real and equal roots” xl = -B / (2.0 x A) x2 = xl
W rite “First root =”, xl W rite “Second root
x2
End
E LSE
Begin
Write “Im aginary roots” xl = -B / (2.0 x A) x2 = xl
yl = V -I) / (2.0 x A) y2 = -yl
W rite “First root”
W rite “Real part”, xl, “Img. part”, yl W rite “Second root ”
Write “Real part”, x2, “Img. part”, y2
End
End
5. END.
11.3.
A L G O R IT M : M assiv elem en tlarin i yig‘n disini aniqlash.
20 elementni yig‘indisini topish kerak. NUM sonlar joyi
aniqlanadi.
SUM y ig ‘indisi saqlanadi.
l.S U M < - 0
2.
NUM <-
277
3. Repeat for COUNT = 1 ,2 ,, 20
Begin
SUM <- SUM + NUM
NUM <- NUM + 4
End
4. Write “Sum of 20 terms is”, SUM
5. End.
Dostları ilə paylaş: |