t=a(j)
a(j)=a(j-1)
a(j-1)=t
EndIf
Next
y=y&a(i)
Next
MsgBox(s&vbCrLf&y)
EndSub
PrivateSubButton16_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton16.Click
DimnAsInteger
DimiAsInteger
DimjAsInteger
DimsAsString
DimtAsString
Dimi_0AsInteger
Dimj_0AsInteger
Dimmfz_bz(9,9)AsString
Dimmfz(9,9)AsString
n=InputBox("请输入魔方阵阶数N")
Ifn<3Orn>9OrnMod2<>1Then
MsgBox("您输入的魔方阵阶数N不在范围内,请输入3-9之间的奇数")
ExitSub
EndIf
'初始化
Fori=1To9
Forj=1To9
mfz_bz(i,j)=0
mfz(i,j)=""
Nextj
Nexti
mfz(1,n\2+1)=1
mfz_bz(1,n\2+1)=1
i_0=1
j_0=n\2+1
Forysz=2Ton*n
Ifmfz(i_0,j_0)>nAnd(mfz(i_0,j_0)Modn=0)Then
i=i_0+1
j=j_0
ElseIfi_0=1Then
i=n
j=j_0+1
ElseIfj_0=nThen
i=i_0-1
j=1
Else
i=i_0-1
j=j_0+1
EndIf
Ifmfz_bz(i,j)=1Then
i=i_0+1
j=j_0
EndIf
mfz(i,j)=ysz
mfz_bz(i,j)=1
i_0=i
j_0=j
Nextysz
MsgBox("魔方阵排列完毕")
s=""
Fori=1To9
Forj=1To9
t=mfz(i,j)
s=s&Format(t,"{0,4}")
Next
s=s&vbCrLf
Next
MsgBox(s)
EndSub
EndClass
实验30
PublicClassForm1
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
DimaAsString,bAsString,cAsString
Dimx1AsSingle,x2AsSingle
a=InputBox("输入A","输入数据Y",,500,500)
b=InputBox("输入B","输入数据Y",,500,500)
c=InputBox("输入C","输入数据Y",,500,500)
x1=-b+Math.Sqrt(b^2-4*a*c)/2/a
x2=-b-Math.Sqrt(b^2-4*a*c)/2/a
MsgBox("x1="&Format(x1,"###.###")&"x2="&Format(x2,"###.###"))
EndSub
PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click
DimxAsInteger
DimyAsInteger
DimzAsSingle
x=5
y=9
z=(x^3+x*y+y^3)/(2*x*y)
MsgBox("(x^3+x*y+y^3)/(2*x*y)="&z)
EndSub
PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click
DimxAsSingle
DimyAsSingle
x=InputBox("输入x")
y=Math.Log(20)+Math.Abs(x-16)
MsgBox("Math.Log(20)+Math.Abs(x-16)="&y)
EndSub
PrivateSubButton4_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton4.Click
DimxAsSingle
DimyAsSingle
x=InputBox("输入x")
y=0.231*x+1.36
MsgBox("0.231*x+1.36="&y)
EndSub
PrivateSubButton5_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton5.Click
ConstgAsSingle=9.81
DimvAsSingle,oAsSingle,tAsSingle,sAsSingle
v=InputBox("输入初速度")
o=InputBox("输入角度")
t=2*v*Math.Sin(o*Math.PI/180)/g
s=v*Math.Sin(2*o*Math.PI/180)/g
MsgBox("落地所需时间"&t&"落地时运动的射程"&s)
EndSub
EndClass
PublicClassForm1
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
DimxAsInteger
x=Int(Rnd()*100)
IfxMod2=0Then
MsgBox(x&"是偶数")
Else
MsgBox(x&"是奇数")
EndIf
EndSub
PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click
DimaAsSingle,bAsSingle,cAsSingle,xAsSingle,yAsSingle
a=InputBox("请输入a")
b=InputBox("请输入b")
c=InputBox("请输入c")
Ifa>bThen
x=a
y=b
Else
x=b
y=a
EndIf
Ifc>xThen
x=c
Else
Ifcy=c
EndIf
EndIf
MsgBox("最大数"&x&"最小数"&y)
EndSub
PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click
DimtAsSingle,fAsSingle
t=InputBox("请输入t")
Ift<120Then
f=0.06*t+2
MsgBox("f=0.06*t+2="&f)
Else
f=0.06*t*0.85
MsgBox("f=0.06*t*0.85="&f)
EndIf
EndSub
PrivateSubButton4_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton4.Click
DimxAsSingle
DimyAsString
x=InputBox("请输入成绩")
Ifx>=90Then
y="A"
ElseIfx>=80Then
y="B"
ElseIfx>=70Then
y="C"
ElseIfx>=60Then
y="D"
Else
y="E"
EndIf
MsgBox("成绩"&x&"等级为"&y)
EndSub
PrivateSubButton5_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton5.Click
DimxAsSingle,yAsSingle
x=InputBox("请输入x")
SelectCasex
CaseIs<=-1
y=x-1
CaseIs<=2
y=2*x
CaseIs<=10
y=x*(x+2)
CaseElse
y=0
EndSelect
MsgBox("y="&y)
EndSub
PrivateSubButton6_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton6.Click
DimaAsString,bAsString,cAsString
Dimx1AsSingle,x2AsSingle,xAsSingle
a=InputBox("输入A","输入数据Y",,500,500)
b=InputBox("输入B","输入数据Y",,500,500)
c=InputBox("输入C","输入数据Y",,500,500)
x=b^2-4*a*c
Ifx>=0Then
x1=-b+Math.Sqrt(x)/2/a
x2=-b-Math.Sqrt(x)/