大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Option Strict Off
发展壮大离不开广大客户长期以来的信赖与支持,我们将始终秉承“诚信为本、服务至上”的服务理念,坚持“二合一”的优良服务模式,真诚服务每家企业,认真做好每个细节,不断完善自我,成就企业,实现共赢。行业涉及会所设计等,在成都网站建设公司、营销型网站建设、WAP手机网站、VI设计、软件开发等项目上具有丰富的设计经验。
Option Explicit On
Friend Class Form1
Inherits System.Windows.Forms.Form
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
Dim j As Integer
Dim A(9) As Short
Dim D(9) As Short
Dim i As Short
Dim B As Short
Dim C As Short
Dim F As Short
Dim G As Boolean
Dim H() As Short
Dim K As Short
Dim S As String
C = 32767
For i = 1 To 10
A(i - 1) = CShort(InputBox("输入第 " i "个数"))
If B A(i - 1) Then B = A(i - 1)
If C A(i - 1) Then C = A(i - 1)
D(i - 1) = Int(Rnd() * 100 + 0.5)
If F D(i - 1) Then F = D(i - 1)
Next i
For i = 2 To 100
For j = 2 To Int(System.Math.Sqrt(i) + 0.5)
'UPGRADE_WARNING: Couldn't resolve default property of object j. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'UPGRADE_WARNING: Mod has a new behavior. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
If i Mod j 0 Then
G = True
Else
G = False
Exit For
End If
Next j
If G = True Then
ReDim Preserve H(K)
H(K) = i
K = K + 1
End If
Next i
S = "2;"
For i = 0 To K - 1
S = S H(i) ";"
Next i
MsgBox("最大数为:" B ";最小数为:" C)
MsgBox("最大的随机数为:" F)
MsgBox("1--100之间共有" K + 1 "个素数:" S)
End Sub
End Class
Dim str As String = "", temp, n As Integer
Dim str1 As String = "12,45,2,9,41,31,66,83,2,1,-9,-91,-21"
Dim a() As String = Split(str1, ",")
For i = 1 To UBound(a) Step 1
a(i) = Val(a(i))
Next
temp = 0
n = 0
For i = 1 To UBound(a)
If a(i) temp Then
temp = a(i)
End If
If a(i) 0 Then
n = n + 1
End If
Next
str = str "正数的个数为 " n
str = str "最大元素的下标为 "
For i = 1 To UBound(a)
If a(i) = temp Then
str = str i " "
End If
Next
TextBox6.Text = str
1、点击VS工具。
2、打开后,新建一个Windows窗体应用程序。
3、新建完毕后,如图所示。
4、拖动一个按钮。
5、定义数组最常见的方法,如图示。
6、运行后,点击按钮,弹出提示正常。
7、定义数组第二种方法,属于动态的方法。
8、运行后,点击按钮,数组成功输出。
private function maxnum(byval a() as integer) as integer
dim i as integer
maxnum=a(0)
for i = 1 to ubound(a)
if a(i)maxnum then maxnum=a(i)
next
end function
你是不是应该对最大值和最小值赋初值(比如把 r(1) 赋给最大值和最小值)呢?不然最小值默认初始值是‘0’,后面的判断就不起作用了。你可以加个断点试试,他们的初始值是多少。。。
'给数组赋值
dim d(6) as integer
d(1)=11
d(2)=32
d(3)=25
d(4)=45
d(5)=9
d(6)=5
'获取最大值(采用打擂台的思路)
dim MyMax as integer
dim i as integer
MyMax = d(1) '假设第1个元素最大
for i = 2 To Ubound(d) '从第2个元素开始到最后一个元素
'如果当前元素比MyMax的值大,就把当前元素保存到MyMax
if d(i) MyMax Then
MyMax = d(i)
end if
next i
msgbox MyMax