1、选择排序
PublicClassForm1
Dima(10)AsInteger
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
DimiAsInteger,jAsInteger,kAsInteger,tAsInteger
Fori=0To10
a(i)=Int(Rnd()*100+1)
Next
Fori=0To9
k=i
Forj=i+1To10
Ifa(k)>a(j)Then
k=j
EndIf
t=a(k)
a(k)=a(i)
a(i)=t
Next
Next
Fori=0To10
Console.Write(a(i)&Space(2))
Next
EndSub
EndClass
2、冒泡排序
PublicClassForm1
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
Dima(10)AsInteger
DimiAsInteger,tAsInteger,kAsInteger
Fori=0To10
a(i)=Int(Rnd()*100+1)
Next
Fori=0To9
Forj=1To10-i
k=j-1
If(a(k)>a(j))Then
t=a(k)
a(k)=a(j)
a(j)=t
EndIf
k=k+1
Next
Next
Fori=0To10
Console.Write(a(i)&Space(2))
Next
EndSub
EndClass
3、求1到100内的素数
PublicClassForm1
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
Dimn%,j%,i%
j=Val(InputBox("输入","n值"))
Forn=1Toj
Fori=2ToMath.Sqrt(n)
If(nModi=0)Then
ExitFor
EndIf
Next
If(i>Math.Sqrt(n))Then
Label1.Text=Label1.Text&n
EndIf
Next
EndSub
EndClass
Dima%,b%,c%
Fora=0To10
Forb=0To10
Forc=0To10
Ifa*a+b*b+c*c=100Then
Label1.Text=Label1.Text&a&b&c&vbCrLf
EndIf
Next
Next
Next
不断更新中,敬请期待。
原文链接:https://www.f2er.com/vb/258868.html