VB编程求1-2!+3!-4!+5!-……n!,并将结果显示在窗体上,其中输入n由输入对话框输入并且1≤n≤10。

VBb编程在窗体上添加一个Picture控件,在Picture控件上用随机颜色画100个同心园,圆心在Picture控件的中心,圆的大小在0到Picture控件边界内变化。

n=val(inputbox("请输入N"))
t=1
for i=1 to n
jc=1
for j=1 to i
jc=jc*j
next
s=s+t*jc
t=-t
next
print s
第二题:

Dim x
Picture1.AutoRedraw = True
Picture1.Height = Picture1.Width
x = Picture1.ScaleWidth
Print x
Picture1.ScaleHeight = x
Picture1.Scale (-x / 2, x / 2)-(x / 2, -x / 2)

Randomize
For i = 1 To 100
Picture1.Circle (0, 0), x / 2 * Rnd, QBColor(Int(16 * Rnd))
Next
相信我 我的算法是比较优化的
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-05-31
Rem 点击command1,求和,点击command2,画圆

Private Sub Command1_Click()
Dim n,i,j,jc,s
k:
n = Val(InputBox("请输入n(1≤n≤10):", , 10))
If n < 1 Or n > 10 Then MsgBox "n输入错误,请重试!": GoTo k
For i = 1 To n
jc = 1
For j = 1 To i
jc = jc * j
Next
s = s + jc * (-1) ^ (i Mod 2 + 1)
Next
Print s
End Sub

Private Sub Command2_Click()
Dim x
Picture1.AutoRedraw = True
Picture1.Height = Picture1.Width
x = Picture1.ScaleWidth
Print x
Picture1.ScaleHeight = x
Picture1.Scale (-x / 2, x / 2)-(x / 2, -x / 2)

Randomize
For i = 1 To 100
Picture1.Circle (0, 0), x / 2 * Rnd, QBColor(Int(16 * Rnd))
Next
End Sub
相似回答
大家正在搜