Algoritm PDF

Embed Size (px)

Citation preview

.

1

, , , , . , , - , . 1. . . , , . . , , . . . , . , . , . 1. . . 2. . .

1

.

2

3. . . 4. . . 5. . . . : 2 + + =0 . 1. , , 2. D=B2 + 4AC 3. D >=0 4.- 5.- 4. x1=(-B + D )/(2*A) , x2=(-B - D )/(2*A) 6. 5. . 7. . 6. 1 , 2 - . 7. . : 1. . 7 . 2. . , , , . 3. . , , . 4. . . 5. . =5, =8, =-4 , , .

2

.

3

2. , , , - . . , , Z 1, 23, 2, 5, . . , . , , . , . / / . A, B, X1, Y3, Z12 . , . . - , . Rooms(k,t) , k=1,2,3; t=1,2,3, 4 ; Rooms , A(k) , k=1..15 15 . . . , .

3

.

4

: NR NR(k), k=1,2,3, . . 45 . . . 45 . - s , j , , t ST s =1 . . 7; j = 1 . . 8; k=1 . .4; t = 1 . . 25 ST(s, j, k, t) - s ,j , k , t , 78425= 5600 . N , M A=|| akt || k=1. . N, t=1 . .M, , NxM . , , , , , , , . . , , , . , , , . 3. , , . Visual Basic , .

4

.

5

Visual Basic 1. . , . . : , 26 A a, B b, .., Z z 0,1,2,3,5,6,7,8,9 , , , +,-,*,/ \ : 11 \ 3 =3 Mod : 11 mod 3=2 . ^ : 2^3 = 8 > < => 0, Val(458)=> 458 Str(m) M / / . Str(455)=>455 .

7

.

8

n // . / / .

Space$(n), Space(n) Ucase(A), / Lcase(A)/

4. . , , . Dim , As . , Dim A, B, C As Integer , , Dim X, Y, T As Single , , . Dim As . - Integer, Long, Single, Double, String, Boolean, Byte . . . . : Integer % AB%, X1% , YB12% Long & X&, U& Single ! A!, B!, D2! Double # X#, B4#, C# Currency @ V@, Z@, J@ String $ A$, B$, C$ Dim . Dim . , Dim A(15), B(10, 25), C(5, 8, 10) As Double A , 15 , , 1025=250 , , 5810=400 . 8

.

9

4. . , , - . , , , , , , . . 1. 2. 3. 4. 5. . 5 . . : a x+ y+z a+b+c x+ y a+b x yz Sin n x Sinx NN

A / (x+y+z) (a+b+c) / (x+y) (a+b) / (x*y*z) Sin(x)^n Sin(x^n)X ^(M / N)

A / x+y+z a+b+c /( x+y) (a+b+c) / x+y (a+b)/x*y*z a+b/ (x*y*z) Sin^n(x) Sin(x)^n Sqr(x)^M^(1/N) (X ^Y)^Z 9

XM XYZ

X^(Y^Z)

.

10

. , , , = AND, OR, NOT . A=0 Then If D>0 Then X1=(- B + Sqr(D))/ (2*A) : X2=(- B - Sqr(D))/ (2*A) Else X1 = - B/ (2*A) : X2 = X1 End If MsgBox X1 = +Str(X1) + X2 = + Str(X2), Else MsgBox End If End Sub22 . 23 A, B, CD = B^2 - 4*A*C 0 D>=01D>0 1X12=(-B sqr(D))/(2*A) X1= -B/(2*A) , X2=X10 X1 , X2 D>=0 D>0 . . /1/ - . / 0 / . .23 . 24 If Then End If 1 0 -2. . M N :N mod M = 0 1 0. .24 . 25 IfN mod M = 0 Then MsgBox End If ..... . . 1, 2, 3, . . . / / . .p p1 oper1 p2 oper2 p3 oper3 . . . . .... pkoperk-3. 0, 1, 2, . . . , 9, A, B, C, D, E, F . 16- 16- . N P=N mod 16 P 0 pp Case p7 To p8, p9, p10, p11 To p12 P p7 p8 , 9, 10 11 12 Case Else 27 . 28 End Select End Select - Case . -3 Select Case : Sub Dec_Hex2() N= Val(InputBox( N=, Decimal number)) P= N mod 16 Select Case P Case 10 Uld=A Case 11 Uld=B Case 12 Uld=C Case 13 Uld=D Case 14 Uld=E Case 15 Uld=F Case Else Uld=Str(P) End Select MsgBox Uldegdel=+ Uld, Ur dun End Sub : Case Else Case 0 To 9 . Goto Label . . 40- . 28 . 29 : Label: . Label: . . Goto Label . Label: Goto Label . . . , . , . . . , , . , . : , . /TRUE/ , /FALSE/ . Do While / Loop / / Do /Loop While / / Do Until / Loop / / Do / Loop Until / / . -TRUE /1/ - .29 :. 30 0 1 0 1 . . - . 1 1 0 0. . . Do Loop While Do While Loop - FALSE /0/ . . TRUE /1/ - .30 . 31 . TRUE /1/ - . FALSE /0/ - . -4 S = k - k =1 k + 12 N, - , . . - N k=1, S=0 S=S+k/(k2+1) k=k+1 k M N = N M = (k1-k2)*E, k1 k2 0 M > N M = M N = (k2 k1)*E, k2 k1 0 N = , M = E . B = N*M /E . N > M, M > N N = N M M = M - N N = M . . . N M N1, M1 N, M .35 . 36 -N, MN1=N, M1=MN=N-M1N>M0M>N1M=M-N(a)()0B=N1*M1 /MM, B 36 . 37 . N, MN1=N, M1=M N>M (a)1 0M>N () N=N-M 1 M=M-N 0B=M1*N1 / M M, B -5 - . Sub MaxMin_div() N=Val(InputBox(N=, 1 st number)) M=Val(InputBox(M=, 2nd number)) N1=N : M1=M Do Until N=M N=M 2 If N>M Then N=N-M Else If M>N Then M N M=M-N End If End If Loop N=M Loop . M N . XB=N1*M1/ M MsgBox XIEX=+Str(M)+ XBEX=+Str(XB), Ur dun End Sub 37 N M . 38 : - () N=N-M , () M=M-N N=M . Do Until N=M . -6. N . . 2 - , N=2 , . . (t) t=0 , t 0 .38 . 39 - : N M=cint(N/2) t=0 k=2k=M Then Do N=N-M:T=T+1 Loop While N>=M MsgBox Nogdvor =+Str(T)+ Uldegdel=+Str(N),vbOkOnly, Shiid Else MsgBox Nogdvor =+Str(T)+ Uldegdel=+Str(N), vbOkOnly, Shiid End If End Sub42 . 43 . . . . : 1. K = A 2. 3. : K =K + 4. K B, B+C>A . . A B C 1 A+B >C 0 A+C>B 0 1 B+C>A 0 1P=(A+B+C)/2S = SQR(P*(P-A)*(P-B)*(P-C)) S 48 . 49 - / temdeg: / . : Sub abc() temdeg: A=Val(Inputbox(A=, A tal)) B=Val(Inputbox(B=, B tal)) C=Val(Inputbox(C=, C tal)) If A+B>C Then If A+C>B Then If B+C>A Then P=(A+B+C)/2 : S=SQR(P*(P-A)*(P-B)*(P-C)) Else Goto temdeg End If Else Goto temdeg End IF Else Goto temdeg End If Debug.Print S=;S End Sub 10. // . . 16 9 1 16 1 9 . 9 16 . i, j , 9x16=144 / / D(i, j) , i =1..9, j=1..16 . - . 49 . 50 i=1 j=1 D(i, j ) j = j +1 1 j x(i) Then Min = x(i): mi = i End If End If Next i Debug.Print "Max="; Max; "ma="; ma Debug.Print "Min="; Min; "mi="; mi End Sub-13. X(k), k = 1. .N - . . (k) k=1..N . X(1) X(2) X(3) . . . . X(N-1) X(N) , . . , . . . . 52 . 53 A(1) A(2), A(3), . . . . . A(N) A(2) A(3), A(4) . . . . A(N) A(3) A(4), A(5) . . A(N) . . . . . . . . . . . . . . . . . . . . . . A(N-1) . . . . . . . . . . . . . A(N) . . A(i) A(j ) - C=A(i): A(i)=A(j ): A(j )=C . - : k=1 j=k+1 0 A(k) > A(j ) 1 A(k) , A(j ) j=j+1 1 j 0 Then Fact = X*Fact(X-1) Else Exit function End If End Function , 0!=1 X=0 Fact=1, X>0 - (-1) (Fact=X*Fact(X-1)) , / / (Exit function) .57 . 58 Sub Selgemel() N=Val(Inputbox(N=, Khedees) M=Val(Inputbox(M=, Khedeer) X=N: S1=Fact(X) X=M: S2=Fact(X) X=N-M: S3=Fact(X) S=S1/(S2*S3) Debug.Print S=;S End Sub . -10. F(a,x) = aX . - F(a,x) = aX . > 0 / , /, = 0, 1, 2, 3, 4, . . . . . : =0 F(a,0) = a0 =1 x=1 F(a,1)=a1 = a * a0 = a * F(a, 0) x=2 F(a,2)=a2 = a * a1 = a * F(a, 1) x=3 F(a,3)=a3 = a * a2 = a * F(a, 2) . . . . . . . . . . . . . . . . . . x F(a,x)=ax = a * aX-1 = a * F(a, x-1) . x= -1, -2, -3, -4 , . . . F(a, -1)=a-1 =1 / a F(a, -1) =1 / F(a,1) , F(a, -2) =1 / F(a,2), F(a, -3) =1 / F(a,3) . x = 0 F(a, x) = 1 x > 0 F(a, x)=a * F(a, x-1) x < 0 F(a, x)=1/ F(a, abs(x)) . - :58 . 59 x=0 0 x>0 1 F(a,x)=1/ F(a, abs(x))1F(a, x) = 11F(a , x)=a *F(a, x-1) , F - . : Function F(a,x) If x=0 Then F=1 ElseIf x>0 Then F = a * F(a, x-1) Else F = 1 / F(a,x) End If End Functionk N N -11. S = K =1 ( N k )!K . . . :59 . 60 Sub ssum() N=Val(InputBox(N=)) S=0 For k = 0 To N S = S + 1 / Fact(k) Next k Debug.Print S=; S End Sub Function Fact (X) If X=0 Then Fact = 0 ElseIf X>0 Then Fact = X * Fact (X-1) Else Exit function End If End Function Function F(B, X) If X = 0 Then F=1 ElseIf X>0 Then F = B * F(B, X-1) Else F = 1/ F(B, X) End If End Function Sub ssum() N=Val(InputBox(N=)) S=0 k=1 DO A=k / N S = S + F(A, k)/ Fact(N-k) k=k+1 Loop While k0 Then Fact = X * Fact (X-1) Else Exit function End If End Function -------------------------Function F(B, X) If X = 0 Then F= 1 ElseIf X>0 Then F = B * F(B, X-1) Else F = 1/ F(B, X) End If End Function60 . 61 Sin1 Sin1 + Sin 2 Sin1 + Sin 2 + ...... + SinN + + ...... + 2 ln 2 ln 3 ln N ( N + 1)-12. S = A=Log(k+1) . Sub ss_too() X=Val(InputBox(X=)) N=Val(InputBox(N=)) S = 0:Z=0 k=1 DO Z=Z+Sink : A=Log(k+1) S = S + Z / F(A, k) k=k+1 Loop While k0 Then Fact = X * Fact (X-1) Else Exit function End If End Function -------------------------Function F(B, X) If X = 0 Then F=1 ElseIf X>0 Then F = B * F(B, X-1) Else F = 1/ F(B, X) End If End Function Sub ss1_too() N=Val(InputBox(N=)) S = 0:Z=0 For k = 0 To N Z=Z+Sink : A=Log(k+1) S = S + Z / F(A, k) Next k Debug.Print S=; S End Sub --------------------------Function Fact (X) If X=0 Then Fact = 0 ElseIf X>0 Then Fact = X * Fact (X-1) Else Exit function End If End Function --------------------------Function F(B, X) If X = 0 Then F=1 ElseIf X>0 Then F = B * F(B, X-1) Else F = 1/ F(B, X) End If End Function61 . 62 12. , , . . , , . , . , , . : Output Open FileName For Output As #FileNumber . . . . Write #FileNumber, [variables, . . , . . ] . . . Close # FileNumber Open FileName For Input As #FileNumber . . . . Input #FileNumber, [variables, . . , . . ] . . . Close # FileNumber Open FileName For Append As #FileNumber . . . . Write #FileNumber, [variables, . . , . . ] . . . Close # FileNumber Input Append FileName . C:\ Windows\ Toocoo.dat Windows Toocoo.dat . Open As FileNumber- Close 62 . 63 [Variables] , . #FileNumber . Write - . Input - . Append - . -13. / Ner /, /Calin/, / Day/ /Calin.dat / , . . calin < 50000 =0 50000< calin