Dim x As Single, n As Single, y As Single
'
x = Val(InputBox(" x"))
n = Val(InputBox(" n"))
'
If x >= 0 And n >= 0 Then y = Sqr(x)
If x < 0 And n < 0 Then y = n * x + 2
MsgBox (y) '
End Sub
6.3. y x:
If:
Sub CommandButton3_Click()
Dim x As Single, y As Single
'
x = Val(InputBox(" x"))
'
If x < 0 Then y = x + 2 Else If x <= 5 Then y = Sqr(5 * x) Else y = x ^ 2
MsgBox (y) '
End Sub
6.4. If y w : < 5, y = sin2 x, w = ctg x; ³ 5, y = 1 sin x, w = arctg x.
= {9; 0.1; -4; 5; 12} . :
Private Sub CommandButton4_Click()
Dim x As Single, y As Single, z As Single
Dim w As Single, I As Integer
For i = 1 to 5
x = Cells(I, 1)
If x > 5 Then
y = Sin(x) ^ 2
w = cos(x) / sin(x)
Else
y = 1 - Sin(x)
w = Atn(x)
End If
Cells(i, 2) = y
Cells(i, 3) = w
Next
End Sub
, , (Worksheets ()).
, ,
, .
6.5. b = {5.2; 4.5; 1; 2.9; 3}. :
b . B1:
Sub CommandButton5_Click()
Dim b As Single, s As Single, i As Integer
s = 0
For i = 1 To 5
b = Cells(i,1)
s = s + b
Next
Range(B1) = s
End Sub
6.6. t = {0.4; 1.5; 2.8; 3; 0.9; 7.3} s
.
. D1:
Sub CommandButton6_Click()
Dim t As Single, s As Single
Dim p As Single, k As Integer
p = 1
For k = 1 To 6
t = Cells(k, 3)
p=p * sin(t)
Next
s = 2.4 + p
Range(D1) = s
End Sub
6.7. d = {12; 0.4; 30; 2; 5; 9.3} . . F1 F2:
Sub CommandButton7_Click()
|
|
Dim d As Single, max As Single, n As Integer, i As Integer
max = Cells(1, 5): n = 1
For i = 2 To 6
d = Cells(i, 5)
If d > max Then max = d: n = i
Next
Range(F1) = max
Range(F2) = n
End Sub
, . .
, a(i), a ; i .
Dim, :
Dim a(5) As Single
, . . .
, . , (i) : (0), (1), (2), (3), (4), (5).
, 5 10, :
Dim a(5 to 10) As Single
: (5), (6), (7), (8), (9), (10).
.
6.8. :